LEADTOOLS (Leadtools assembly)
LEAD Technologies, Inc

WindowLevel Method

Example 





Value indicating the low bit used for leveling. 0 <= LowBit <= HighBit <= (11 for 12-bit grayscale or 15 for 16-bit grayscale).
Value indicating the high bit used for leveling. 0 <= LowBit <= HighBit <= (11 for 12-bit grayscale or 15 for 16-bit grayscale).
Optional 8-bit lookup table that can be used to implement a user defined conversion. For every intensity value between 0 and 2 raised to the power of (HighBit - LowBit + 1)-1 there should be a corresponding entry in the lookup table that contains a color. If palette is null (Nothing in Visual Basic), the conversion is a normal shift (right or left) and the painted image is 8-bit grayscale. If palette is not null (Nothing in Visual Basic), the painted image is a 24-bit image.
Value indicating whether palette is used by the paint and image processing methods or only by the paint methods.
Sets up the paint or paint and image processing methods' window leveling options for this RasterImage .NET support Silverlight support WinRT support
Syntax
public void WindowLevel( 
   int lowBit,
   int highBit,
   RasterColor[] palette,
   RasterWindowLevelMode mode
)
'Declaration
 
Public Sub WindowLevel( _
   ByVal lowBit As Integer, _
   ByVal highBit As Integer, _
   ByVal palette() As RasterColor, _
   ByVal mode As RasterWindowLevelMode _
) 
'Usage
 
Dim instance As RasterImage
Dim lowBit As Integer
Dim highBit As Integer
Dim palette() As RasterColor
Dim mode As RasterWindowLevelMode
 
instance.WindowLevel(lowBit, highBit, palette, mode)
public void WindowLevel( 
   int lowBit,
   int highBit,
   RasterColor[] palette,
   RasterWindowLevelMode mode
)
 function Leadtools.RasterImage.WindowLevel( 
   lowBit ,
   highBit ,
   palette ,
   mode 
)
public:
void WindowLevel( 
   int lowBit,
   int highBit,
   array<RasterColor>^ palette,
   RasterWindowLevelMode mode
) 

Parameters

lowBit
Value indicating the low bit used for leveling. 0 <= LowBit <= HighBit <= (11 for 12-bit grayscale or 15 for 16-bit grayscale).
highBit
Value indicating the high bit used for leveling. 0 <= LowBit <= HighBit <= (11 for 12-bit grayscale or 15 for 16-bit grayscale).
palette
Optional 8-bit lookup table that can be used to implement a user defined conversion. For every intensity value between 0 and 2 raised to the power of (HighBit - LowBit + 1)-1 there should be a corresponding entry in the lookup table that contains a color. If palette is null (Nothing in Visual Basic), the conversion is a normal shift (right or left) and the painted image is 8-bit grayscale. If palette is not null (Nothing in Visual Basic), the painted image is a 24-bit image.
mode
Value indicating whether palette is used by the paint and image processing methods or only by the paint methods.
Remarks

This method is available in the (Document/Medical only) Toolkits.

Provides "on demand" window leveling for the paint methods and does not alter the image data. To convert the image data to a window leveled image, use Leadtools.ImageProcessing.Core.WindowLevelCommand.

If RasterWindowLevelMode.PaintAndProcessing is specified, then all image processing methods will take the palette into account.

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 mode parameter, by using the Leadtools.ImageProcessing.Core.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

For a version of this function that uses an 8-bit palette, see WindowLevelExt.

Saving Window-Leveled Images.

LEADTOOLS supports two types of LUTs for 10-16-bit grayscale images (8-bit LUT and 16-bit LUT). Typical grayscale image display and processing is done using an 8-bit LUT. But, you can also use a 16-bit LUT, which offers more precision. Some special video cards and monitors also support display of grayscale images using a 16-bit LUT.

For more information, refer to Introduction to Image Processing With LEADTOOLS.

For more information, refer to Grayscale Images.

Example
 
Public Sub WindowLevelExample()
      Dim codecs As RasterCodecs = New RasterCodecs()
      ' Load an image that has BottomLeft ViewPerspective
      Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP"))

      ' Change the image to 16-bit grayscale 
      Dim grayscaleCmd As GrayscaleCommand = New GrayscaleCommand(16)
      grayscaleCmd.Run(image)

      Dim minMaxBitsCmd As MinMaxBitsCommand = New MinMaxBitsCommand()
      minMaxBitsCmd.Run(image)

      Dim minMaxValuesCmd As MinMaxValuesCommand = New MinMaxValuesCommand()
      minMaxValuesCmd.Run(image)

      Dim lowBit As Integer = minMaxBitsCmd.MinimumBit
      Dim highBit As Integer = minMaxBitsCmd.MaximumBit

      Dim size As Integer = (1 << (image.HighBit - image.LowBit + 1))
      Dim palette As RasterColor() = New RasterColor(size - 1) {}

      ' fill the first half of the LUT with RED
      Dim x As Integer = 0
      Do While x < size / 2
         palette(x).R = 255
         palette(x).G = 0
         palette(x).B = 0
         palette(x).Reserved = 0
         x += 1
      Loop

      Dim minVal As Integer = minMaxValuesCmd.MinimumValue
      Dim maxVal As Integer = minMaxValuesCmd.MaximumValue

      ' Fill the rest with gray values 
      x = (size \ 2)
      Do While x < size
         palette(x).R = Convert.ToByte(Math.Min(255, ((x - minVal) * 255 / (maxVal - minVal))))
         palette(x).G = palette(x).R
         palette(x).B = palette(x).R
         palette(x).Reserved = 0
         x += 1
      Loop
      image.WindowLevel(lowBit, highBit, palette, RasterWindowLevelMode.PaintAndProcessing)

      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_WindowLevel.BMP"), RasterImageFormat.Bmp, 0)

      image.Dispose()
      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void WindowLevelExample()
   {
      RasterCodecs codecs = new RasterCodecs();
      // Load an image that has BottomLeft ViewPerspective
      RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP"));

      // Change the image to 16-bit grayscale 
      GrayscaleCommand grayscaleCmd = new GrayscaleCommand(16);
      grayscaleCmd.Run(image);

      MinMaxBitsCommand minMaxBitsCmd = new MinMaxBitsCommand();
      minMaxBitsCmd.Run(image);

      MinMaxValuesCommand minMaxValuesCmd = new MinMaxValuesCommand();
      minMaxValuesCmd.Run(image);

      int lowBit = minMaxBitsCmd.MinimumBit;
      int highBit = minMaxBitsCmd.MaximumBit;

      int size = (1 << (image.HighBit - image.LowBit + 1));
      RasterColor[] palette = new RasterColor[size];

      // fill the first half of the LUT with RED
      for(int x = 0; x < size / 2; x++)
      {
         palette[x].R = 255;
         palette[x].G = 0;
         palette[x].B = 0;
         palette[x].Reserved = 0;
      }

      int minVal = minMaxValuesCmd.MinimumValue;
      int maxVal = minMaxValuesCmd.MaximumValue;

      // Fill the rest with gray values 
      for(int x = (size / 2); x < size; x++)
      {
         palette[x].R = Convert.ToByte(Math.Min(255, ((x - minVal) * 255 / (maxVal - minVal))));
         palette[x].G = palette[x].R;
         palette[x].B = palette[x].R;
         palette[x].Reserved = 0;
      }
      image.WindowLevel(lowBit, highBit, palette, RasterWindowLevelMode.PaintAndProcessing);

      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_WindowLevel.BMP"), RasterImageFormat.Bmp, 0);

      image.Dispose();
      codecs.Dispose();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
RasterImageExamples.prototype.WindowLevelExample = function ( )
{
   Tools.SetLicense ( ) ;

   with (Leadtools) {
      with (Leadtools.Codecs) {
         with (Leadtools.ImageProcessing.Core) {

            var codecs = new RasterCodecs();
            // Load an image that has BottomLeft ViewPerspective
            var srcFileName = "Assets\\Image1.cmp";
            var image;
            return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
               return codecs.loadAsync(LeadStreamFactory.create(loadFile))
            })
               .then(function (img) {
                  image = img;

                  // Change the image to 16-bit grayscale 
                  var grayscaleCmd = new Leadtools.ImageProcessing.GrayscaleCommand(16);
                  grayscaleCmd.run(image);

                  var minMaxBitsCmd = new MinMaxBitsCommand();
                  minMaxBitsCmd.run(image);

                  var minMaxValuesCmd = new MinMaxValuesCommand();
                  minMaxValuesCmd.run(image);

                  var lowBit = minMaxBitsCmd.minimumBit;
                  var highBit = minMaxBitsCmd.maximumBit;

                  var size = (1 << (image.highBit - image.lowBit + 1));

                  var palette = new Array(size);

                  // fill the first half of the LUT with RED
                  for (var x = 0; x < size / 2; x++) {
                     var color = [];
                     color.a = 255;
                     color.r = 255;
                     color.g = 0;
                     color.b = 0;
                     color.reserved = 0;
                     palette[x] = color;
                  }

                  var minVal = minMaxValuesCmd.minimumValue;
                  var maxVal = minMaxValuesCmd.maximumValue;

                  // Fill the rest with gray values 
                  for (var x = (size / 2) ; x < size; x++) {
                     var color = [];
                     color.a = 255;
                     color.r = Math.floor(Math.max(0, Math.min(255, ((x - minVal) * 255 / (maxVal - minVal)))));
                     color.g = color.r;
                     color.b = color.r;
                     color.reserved = 0;
                     palette[x] = color;
                  }
                  image.windowLevel(lowBit, highBit, palette, RasterWindowLevelMode.paintAndProcessing);

                  return Tools.AppLocalFolder().createFileAsync("IMAGE1_WindowLevel.BMP")
               })
                  .then(function (saveFile) {
                     var saveStream = LeadStreamFactory.create(saveFile);
                     return codecs.saveAsync(image, saveStream, RasterImageFormat.bmp, 0)
                  })
                  .then(function () {

                     image.close();
                     codecs.close();
                  });
         }
      }
   }
}
[TestMethod]
public async Task WindowLevelExample()
{
   RasterCodecs codecs = new RasterCodecs();
   // Load an image that has BottomLeft ViewPerspective
   string srcFileName = @"Assets\Image1.cmp";
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
   // Change the image to 16-bit grayscale 
   GrayscaleCommand grayscaleCmd = new GrayscaleCommand(16);
   grayscaleCmd.Run(image);

   MinMaxBitsCommand minMaxBitsCmd = new MinMaxBitsCommand();
   minMaxBitsCmd.Run(image);

   MinMaxValuesCommand minMaxValuesCmd = new MinMaxValuesCommand();
   minMaxValuesCmd.Run(image);

   int lowBit = minMaxBitsCmd.MinimumBit;
   int highBit = minMaxBitsCmd.MaximumBit;

   int size = (1 << (image.HighBit - image.LowBit + 1));

   RasterColor[] palette = new RasterColor[size];

   // fill the first half of the LUT with RED
   for (int x = 0; x < size / 2; x++)
   {
      palette[x].R = 255;
      palette[x].G = 0;
      palette[x].B = 0;
      palette[x].Reserved = 0;
   }

   int minVal = minMaxValuesCmd.MinimumValue;
   int maxVal = minMaxValuesCmd.MaximumValue;

   // Fill the rest with gray values 
   for (int x = (size / 2); x < size; x++)
   {
      palette[x].R = Convert.ToByte(Math.Min(255, ((x - minVal) * 255 / (maxVal - minVal))));
      palette[x].G = palette[x].R;
      palette[x].B = palette[x].R;
      palette[x].Reserved = 0;
   }
   image.WindowLevel(lowBit, highBit, palette, RasterWindowLevelMode.PaintAndProcessing);

   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync("IMAGE1_WindowLevel.BMP");
   ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
   await codecs.SaveAsync(image, saveStream, RasterImageFormat.Bmp, 0);

   image.Dispose();
   codecs.Dispose();
}
public void WindowLevelExample(RasterImage image, Stream destStream)
{
   // Change the image to 16-bit grayscale 
   GrayscaleCommand grayscaleCmd = new GrayscaleCommand(16);
   grayscaleCmd.Run(image);
   MinMaxBitsCommand minMaxBitsCmd = new MinMaxBitsCommand();
   minMaxBitsCmd.Run(image);

   MinMaxValuesCommand minMaxValuesCmd = new MinMaxValuesCommand();
   minMaxValuesCmd.Run(image);

   int lowBit = minMaxBitsCmd.MinimumBit;
   int highBit = minMaxBitsCmd.MaximumBit;

   int size = (1 << (image.HighBit - image.LowBit + 1));
   RasterColor[] palette = new RasterColor[size];

   // fill the first half of the LUT with RED
   for (int x = 0; x < size / 2; x++)
   {
      palette[x].R = 255;
      palette[x].G = 0;
      palette[x].B = 0;
      palette[x].Reserved = 0;
   }

   int minVal = minMaxValuesCmd.MinimumValue;
   int maxVal = minMaxValuesCmd.MaximumValue;

   // Fill the rest with gray values 
   for (int x = (size / 2); x < size; x++)
   {
      palette[x].R = Convert.ToByte(Math.Min(255, ((x - minVal) * 255 / (maxVal - minVal))));
      palette[x].G = palette[x].R;
      palette[x].B = palette[x].R;
      palette[x].Reserved = 0;
   }
   image.WindowLevel(lowBit, highBit, palette, RasterWindowLevelMode.PaintAndProcessing);

   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, destStream, RasterImageFormat.Bmp, 0);

   image.Dispose();
}
Public Sub WindowLevelExample(ByVal image As RasterImage, ByVal destStream As Stream)
   ' Change the image to 16-bit grayscale 
   Dim grayscaleCmd As GrayscaleCommand = New GrayscaleCommand(16)
   grayscaleCmd.Run(image)
   Dim minMaxBitsCmd As MinMaxBitsCommand = New MinMaxBitsCommand()
   minMaxBitsCmd.Run(image)

   Dim minMaxValuesCmd As MinMaxValuesCommand = New MinMaxValuesCommand()
   minMaxValuesCmd.Run(image)

   Dim lowBit As Integer = minMaxBitsCmd.MinimumBit
   Dim highBit As Integer = minMaxBitsCmd.MaximumBit

   Dim size As Integer = (1 << (image.HighBit - image.LowBit + 1))
   Dim palette As RasterColor() = New RasterColor(size - 1){}

   ' fill the first half of the LUT with RED
   Dim x As Integer = 0
   Do While x < size / 2
      palette(x).R = 255
      palette(x).G = 0
      palette(x).B = 0
      palette(x).Reserved = 0
      x += 1
   Loop

   Dim minVal As Integer = minMaxValuesCmd.MinimumValue
   Dim maxVal As Integer = minMaxValuesCmd.MaximumValue

   ' Fill the rest with gray values 
   x = (size / 2)
   Do While x < size
      palette(x).R = Convert.ToByte(Math.Min(255, ((x - minVal) * 255 / (maxVal - minVal))))
      palette(x).G = palette(x).R
      palette(x).B = palette(x).R
      palette(x).Reserved = 0
      x += 1
   Loop
   image.WindowLevel(lowBit, highBit, palette, RasterWindowLevelMode.PaintAndProcessing)

   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(image, destStream, RasterImageFormat.Bmp, 0)

   image.Dispose()
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

RasterImage Class
RasterImage Members
WindowLevelExt Method
Leadtools.ImageProcessing.Core.WindowLevelCommand
WindowLevelExt Method

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.