Leadtools.ImageProcessing.Core Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.10
WindowLevelCommand Class
See Also  Members   Example 
Leadtools.ImageProcessing.Core Namespace : WindowLevelCommand Class




Converts a 12 or 16-bit grayscale image to an 8-bit grayscale or a 24-bit RGB image. This class is available in Medical toolkits only.
This method is available in the (Document/Medical only) Toolkits.

Syntax

Visual Basic (Declaration) 
Public Class WindowLevelCommand 
   Inherits RasterCommand
   Implements IRasterCommand 
Visual Basic (Usage)Copy Code
Dim instance As WindowLevelCommand
C# 
public class WindowLevelCommand : RasterCommand, IRasterCommand  
Managed Extensions for C++ 
public __gc class WindowLevelCommand : public RasterCommand, IRasterCommand  
C++/CLI 
public ref class WindowLevelCommand : public RasterCommand, IRasterCommand  

Example

Visual BasicCopy Code
ImageProcessing.Core.WindowLevelCommand
   Public Sub WindowLevelCommandExample()
      RasterCodecs.Startup()
      Dim codecs As New RasterCodecs()
      codecs.ThrowExceptionsOnInvalidImages = True

      Dim leadImage As RasterImage = codecs.Load("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Master.jpg")

      ' Prepare the command
      'Change the image to 16-bit grayscale
      Dim graycommand As GrayscaleCommand = New GrayscaleCommand(16)
      Dim command As WindowLevelCommand = New WindowLevelCommand
      graycommand.Run(leadImage)

      Dim minValue As Integer = leadImage.MinValue
      Dim maxValue As Integer = leadImage.MaxValue
      Dim minBit As Integer = leadImage.LowBit
      Dim maxBit As Integer = leadImage.HighBit

      Dim Size As Integer = (1 << (maxBit - minBit + 1))
      Dim LookupTable() As RasterColor
      ReDim LookupTable(Size - 1)

      ' fill the first half of the LookupTable with RED.
      Dim x As Integer
      For x = 0 To Size \ 2 - 1
         LookupTable(x) = New RasterColor(255, 0, 0)
      Next

      ' fill the rest with gray values.
      For x = Size \ 2 To Size - 1
         Dim y As Byte = Convert.ToByte((x - minValue) * 255 / (maxValue - minValue))
         LookupTable(x) = New RasterColor(y, y, y)
      Next

      command.HighBit = maxBit
      command.LowBit = minBit

      command.LookupTable = LookupTable
      command.Order = RasterByteOrder.Bgr
      command.Run(leadImage)

      RasterCodecs.Shutdown()
   End Sub
C#Copy Code
ImageProcessing.Core.WindowLevelCommand 
      public void WindowLevelCommandExample() 
      { 
         // Load an image 
         RasterCodecs.Startup(); 
         RasterCodecs codecs = new RasterCodecs(); 
         codecs.ThrowExceptionsOnInvalidImages = true; 
 
         RasterImage image = codecs.Load(@"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Master.jpg"); 
 
         // Prepare the command 
         int x; 
         byte y; 
         int Size; 
         RasterColor [] LookupTable; 
 
         //Change the image to 16-bit grayscale 
         GrayscaleCommand graycommand = new GrayscaleCommand(16); 
         MinMaxBitsCommand MinMaxBits = new MinMaxBitsCommand(); 
         MinMaxValuesCommand MinMaxValues = new MinMaxValuesCommand(); 
         WindowLevelCommand command = new WindowLevelCommand(); 
 
         graycommand.Run(image); 
         MinMaxBits.Run(image); 
         MinMaxValues.Run(image); 
 
         Size = (1 <<(MinMaxBits.MaximumBit - MinMaxBits.MinimumBit + 1)); 
         LookupTable = new Leadtools.RasterColor[Size]; 
 
         // fill the first half of the LookupTable with RED. 
         for(x = 0; x < Size / 2; x++) 
            LookupTable[x] = new Leadtools.RasterColor(255, 0, 0); 
 
         // fill the rest with gray values. 
         for(x = Size / 2; x < Size; x++) 
         { 
            y = (byte)((x - MinMaxValues.MinimumValue) * 255 / (MinMaxValues.MaximumValue - MinMaxValues.MinimumValue)); 
            LookupTable[x] = new Leadtools.RasterColor(y, y, y); 
         } 
 
         command.HighBit = MinMaxBits.MaximumBit; 
         command.LowBit  = MinMaxBits.MinimumBit; 
         command.LookupTable = LookupTable; 
         command.Order = Leadtools.RasterByteOrder.Bgr; 
 
         command.Run(image); 
 
         RasterCodecs.Shutdown(); 
      }

Remarks

  • This command supports 12 and 16-bit grayscale. Support for 12 and 16-bit grayscale images is available only in the Document/Medical toolkits.
  • This command does not support 32-bit grayscale images.
Only TIFF and DICOM file formats are capable of saving images that have been window-leveled. Images can be window-leveled by calling WindowLevel and specifying RasterWindowLevelMode.PaintAndProcessing for the flags parameter, by using the WindowLevelCommand or by loading an image from a file format that supports Window Leveling. If a window-leveled image is saved as any other file format, the image data will be converted before being saved. For more information, refer to Saving Window-Leveled Images.
For more information, refer to Processing an Image.
For more information, refer to Grayscale Images.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.RasterCommand
      Leadtools.ImageProcessing.Core.WindowLevelCommand

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also