←Select platform

WindowLevelExt Method

Sets up the paint or paint and image processing methods' window leveling options for this RasterImage
public void WindowLevelExt( 
   int lowBit, 
   int highBit, 
   RasterColor16[] palette, 
   RasterWindowLevelMode mode 
Public Sub WindowLevelExt( _ 
   ByVal lowBit As Integer, _ 
   ByVal highBit As Integer, _ 
   ByVal palette() As RasterColor16, _ 
   ByVal mode As RasterWindowLevelMode _ 
- (BOOL)windowLevelExt:(NSInteger)lowBitValue  
               palette:(nullable NSArray<LTRasterColor16 *> *)palette  
                 error:(NSError **)error 
public void windowLevelExt( 
  int lowBit,  
  int highBit,  
  RasterColor16[] palette,  
  RasterWindowLevelMode mode 
void WindowLevelExt(  
   int lowBit, 
   int highBit, 
   array<RasterColor16>^ palette, 
   RasterWindowLevelMode mode 


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 16-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, the conversion is a normal shift (right or left) and the painted image is 8 or 16-bit grayscale. If palette is not null, the painted image is a 48-bit image.

Value indicating whether palette is used by the paint and image processing methods or only by the paint methods.


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 WindowLevelExt.

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 WindowLevelExt and specifying RasterWindowLevelMode.PaintAndProcessing for the mode parameter, by using the WindowLevelExt 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.

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 a version of this function that uses an 8-bit palette, see WindowLevel.

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

For more information, refer to Grayscale Images.

using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Dicom; 
using Leadtools.Drawing; 
using Leadtools.Controls; 
using Leadtools.Svg; 
public void WindowLevelExtExample() 
	RasterCodecs codecs = new RasterCodecs(); 
	// Load a 16-bit grayscale image 
	RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir,"DICOM", "image2.dcm")); 
	// Get the min and max values 
	MinMaxBitsCommand minMaxBitsCmd = new MinMaxBitsCommand(); 
	MinMaxValuesCommand minMaxValuesCmd = new MinMaxValuesCommand(); 
	int lowBit = minMaxBitsCmd.MinimumBit; 
	int highBit = minMaxBitsCmd.MaximumBit; 
	int size = (1 << (image.HighBit - image.LowBit + 1)); 
	RasterColor16[] palette = new RasterColor16[size]; 
	// fill the first half of the LUT with RED 
	for (int x = 0; x < size / 2; x++) 
		palette[x].R = RasterColor16.MaximumComponent; 
		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.ToUInt16(Math.Min(RasterColor16.MaximumComponent, (Convert.ToUInt32(x - minVal) * RasterColor16.MaximumComponent) / (maxVal - minVal))); 
		palette[x].G = palette[x].R; 
		palette[x].B = palette[x].R; 
		palette[x].Reserved = 0; 
	image.WindowLevelExt(lowBit, highBit, palette, RasterWindowLevelMode.PaintAndProcessing); 
	codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "DICOM","IMAGE1_WindowLevel.BMP"), RasterImageFormat.Bmp, 0); 
static class LEAD_VARS 
   public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images"; 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Core 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Controls 
Imports Leadtools.Dicom 
Imports Leadtools.Drawing 
Imports Leadtools.Svg 
Public Sub WindowLevelExtExample() 
   Dim codecs As RasterCodecs = New RasterCodecs() 
   ' Load a 16-bit grayscale image 
   Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE2.DCM")) 
   ' Get the min and max values 
   Dim minMaxBitsCmd As MinMaxBitsCommand = New MinMaxBitsCommand() 
   Dim minMaxValuesCmd As MinMaxValuesCommand = New MinMaxValuesCommand() 
   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 RasterColor16() = New RasterColor16(size - 1) {} 
   ' fill the first half of the LUT with RED 
   Dim x As Integer = 0 
   Do While x < size / 2 
      palette(x).R = RasterColor16.MaximumComponent 
      palette(x).G = 0 
      palette(x).B = 0 
      palette(x).Reserved = 0 
      x += 1 
   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.ToUInt16(Math.Min(RasterColor16.MaximumComponent, 
                                               (Convert.ToUInt32(x - minVal) * RasterColor16.MaximumComponent) / (maxVal - minVal))) 
      palette(x).G = palette(x).R 
      palette(x).B = palette(x).R 
      palette(x).Reserved = 0 
      x += 1 
   image.WindowLevelExt(lowBit, highBit, palette, RasterWindowLevelMode.PaintAndProcessing) 
   codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_WindowLevel.BMP"), RasterImageFormat.Bmp, 0) 
End Sub 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images" 
End Class 

Target Platforms

Help Version 21.0.2021.3.5
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly