LEADTOOLS Image Processing (Leadtools.ImageProcessing.Core assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
ApplyModalityLookupTableCommand Class
See Also  Members  
Leadtools.ImageProcessing.Core Namespace : ApplyModalityLookupTableCommand Class



Remaps the image pixels through a LookupTable (LookupTable). This class is available in the Document/Medical Toolkits only. Supported in Silverlight, Windows Phone 7

Object Model

ApplyModalityLookupTableCommand ClassDicomLookupTableDescriptor Class

Syntax

Visual Basic (Declaration) 
Public Class ApplyModalityLookupTableCommand 
   Inherits Leadtools.ImageProcessing.RasterCommand
   Implements IRasterCommand 
Visual Basic (Usage)Copy Code
Dim instance As ApplyModalityLookupTableCommand
C# 
public class ApplyModalityLookupTableCommand : Leadtools.ImageProcessing.RasterCommand, IRasterCommand  
C++/CLI 
public ref class ApplyModalityLookupTableCommand : public Leadtools.ImageProcessing.RasterCommand, IRasterCommand  

Example

Run the Leadtools.ImageProcessing.Core.ApplyModalityLookupTableCommand on an image.

Visual BasicCopy Code
Public Sub ApplyModalityLookupTableCommandExample()
   Dim codecs As New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True

   Dim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE2.dcm"))

   ' Prepare the command
   Dim i As Integer
   Dim pLookupTable() As Short
   ReDim pLookupTable(65535)
   Dim LookupTableDescriptor As DicomLookupTableDescriptor = New DicomLookupTableDescriptor

   ' set a LookupTable which reduces the intensity of each pixel to half
   For i = 0 To 65535
      pLookupTable(i) = CType(i \ 2, Int16)
   Next


   ' fill the LookupTableDescriptor object
   LookupTableDescriptor.FirstStoredPixelValueMapped = 0
   LookupTableDescriptor.EntryBits = 16

   ' apply the LookupTable
   Dim command As ApplyModalityLookupTableCommand = New ApplyModalityLookupTableCommand
   command.Flags = ModalityLookupTableCommandFlags.None
   command.LookupTable = pLookupTable
   command.LookupTableDescriptor = LookupTableDescriptor
   command.Run(leadImage)

End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
public void ApplyModalityLookupTableCommandExample()
   {
      // Load an image
      RasterCodecs codecs = new RasterCodecs();
      codecs.ThrowExceptionsOnInvalidImages = true;

      RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE2.dcm"));

      // Prepare the command
      int                i; 
      short[] pLookupTable = new short[0x10000]; 
      DicomLookupTableDescriptor LookupTableDescriptor = new DicomLookupTableDescriptor();

      // set a LookupTable which reduces the intensity of each pixel to half
      for(i = 0; i <= 0xFFFF; i++)
         pLookupTable[i] = (short)(i / 2);

      // fill the LookupTableDescriptor object
      LookupTableDescriptor.FirstStoredPixelValueMapped = 0; 
      LookupTableDescriptor.EntryBits = 16; 

      // apply the LookupTable
      ApplyModalityLookupTableCommand command = new ApplyModalityLookupTableCommand();
      command.Flags = ModalityLookupTableCommandFlags.None;
      command.LookupTable = pLookupTable;
      command.LookupTableDescriptor = LookupTableDescriptor;
      command.Run(image);

   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
public void ApplyModalityLookupTableCommandExample(RasterImage image, Stream outStream)
{
   // Prepare the command
   int i;
   short[] pLookupTable = new short[0x10000];
   DicomLookupTableDescriptor LookupTableDescriptor = new DicomLookupTableDescriptor();
   // set a LookupTable which reduces the intensity of each pixel to half
   for (i = 0; i <= 0xFFFF; i++)
      pLookupTable[i] = (short)(i / 2);

   // fill the LookupTableDescriptor object
   LookupTableDescriptor.FirstStoredPixelValueMapped = 0;
   LookupTableDescriptor.EntryBits = 16;

   // apply the LookupTable
   ApplyModalityLookupTableCommand command = new ApplyModalityLookupTableCommand();
   command.Flags = ModalityLookupTableCommandFlags.None;
   command.LookupTable = pLookupTable;
   command.LookupTableDescriptor = LookupTableDescriptor;
   command.Run(image);

   // Save result image
   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24);
   image.Dispose();
}
SilverlightVBCopy Code
Public Sub ApplyModalityLookupTableCommandExample(ByVal image As RasterImage, ByVal outStream As Stream)
   ' Prepare the command
   Dim i As Integer
   Dim pLookupTable As Short() = New Short(&H10000 - 1){}
   Dim LookupTableDescriptor As DicomLookupTableDescriptor = New DicomLookupTableDescriptor()
   ' set a LookupTable which reduces the intensity of each pixel to half
   i = 0
   Do While i <= &HFFFF
      pLookupTable(i) = CShort(i / 2)
      i += 1
   Loop

   ' fill the LookupTableDescriptor object
   LookupTableDescriptor.FirstStoredPixelValueMapped = 0
   LookupTableDescriptor.EntryBits = 16

   ' apply the LookupTable
   Dim command As ApplyModalityLookupTableCommand = New ApplyModalityLookupTableCommand()
   command.Flags = ModalityLookupTableCommandFlags.None
   command.LookupTable = pLookupTable
   command.LookupTableDescriptor = LookupTableDescriptor
   command.Run(image)

   ' Save result image
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24)
   image.Dispose()
End Sub

Remarks

  • This class remaps the image pixels through a LookupTable (LookupTable). In the DICOM world, this is referred to as "applying a non-linear Modality LookupTable".
  • This class is similar to Leadtools.ImageProcessing.Color.RemapIntensityCommand because it remaps the image pixel values through a LookupTable. The class differs from Leadtools.ImageProcessing.Color.RemapIntensityCommand as follows:

    ApplyModalityLookupTableCommand allows you to specify an incomplete LookupTable. Values less than the first mapped index will be mapped to the first entry in the palette. Values higher than "first mapped index" + "LookupTable length" will be mapped to the last entry in the LookupTable.

    ApplyModalityLookupTableCommand only works on grayscale images.
    ApplyModalityLookupTableCommand can create signed images. The output image will be signed (if ModalityLookupTableCommandFlags.SignedLookupTable is set), or unsigned (ModalityLookupTableCommandFlags.SignedLookupTable is not set).
  • The values in the LookupTable will be masked such that only the useful bits in the image are considered. The values are considered as if the image pixel values are normalized, Leadtools.RasterImage.LowBit = 0.
  • For example, let's say the image is:

    Leadtools.RasterImage.BitsPerPixel = 12

    Leadtools.RasterImage.LowBit = 4

    Leadtools.RasterImage.HighBit = 10

    In this case, there are 10-4+1=7 valid bits. This means that there are 128 values to remap. For every pixel, ApplyModalityLookupTableCommand will do the following:
  • Take the pixel value, shift it to the right by 4 and mask out the high bits, producing a value (val = 0..127).
  • The value is remapped according to the LookupTable (values smaller than FirstStoredPixelValueMapped (property of DicomLookupTableDescriptor class) are mapped to first LookupTable entry, while values greater than FirstStoredPixelValueMapped (property of DicomLookupTableDescriptor class) + LookupTable->Length are mapped to the last LookupTable entry).
  • After remapping, the value is shifted to the left by 4 and will replace bits 4 thru 10 from the original image.
  • If the image is signed, the indices for the LookupTable are assumed to be signed and be between -32768 and +32767.
  • If the image is unsigned, the indices are unsigned and are between 0..65535.
  • It is recommended to always set the ModalityLookupTableCommandFlags.UpdateMinMax flag.
  • This class is helpful in applying what is referred to as a "Non-Linear Modality LookupTable" in the DICOM world. According to the DICOM standard a "Modality LookupTable" defines the transformation of manufacturer-dependent pixel values into pixel values, which are manufacturer independent (e.g. Hounsfield units for CT, Optical Density for film digitizers, etc.).
  • This class supports 12 and 16-bit grayscale. Support for 12 and 16-bit grayscale is available only in the Document/Medical toolkits.
  • This command does not support 32-bit grayscale images.
For more information, refer to Changing Brightness and Contrast.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.RasterCommand
      Leadtools.ImageProcessing.Core.ApplyModalityLookupTableCommand

Requirements

Target Platforms: Silverlight 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also