←Select platform

WindowLevelCommand Class

Summary
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.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public class WindowLevelCommand : RasterCommand 
@interface LTWindowLevelCommand : LTRasterCommand 
public class WindowLevelCommand 
    extends RasterCommand 
public ref class WindowLevelCommand : public RasterCommand   
class WindowLevelCommand(RasterCommand): 
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.
  • RasterByteOrder.Romm and RasterByteOrder.Gray are not supported by this command.

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. See WindowLevelExtCommand for a version of this class using 16-bit lookup tables. 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.

Window Level Function - Before

Window Level Function - Before

Window Level Function - After

Window Level Function - After

View additional platform support for this Window Level function.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
 
public void WindowLevelCommandExample() 
{ 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE3.dcm")); 
 
   // 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); 
 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.core.*; 
 
 
public void windowLevelCommandExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.setThrowExceptionsOnInvalidImages(true); 
 
   RasterImage image = codecs.load(combine(LEAD_VARS_IMAGES_DIR, "DICOM\\IMAGE3.dcm")); 
 
   // 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.getMaximumBit() - minMaxBits.getMinimumBit() + 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.getMinimumValue()) * 255 
            / (minMaxValues.getMaximumValue() - minMaxValues.getMinimumValue())); 
      lookupTable[x] = new leadtools.RasterColor(y, y, y); 
   } 
 
   command.setHighBit(minMaxBits.getMaximumBit()); 
   command.setLowBit(minMaxBits.getMinimumBit()); 
   command.setLookupTable(lookupTable); 
   command.setOrder(RasterByteOrder.BGR); 
 
   int change = command.run(image); 
   assertTrue(change != RasterImageChangedFlags.NONE); 
 
   codecs.save(image, combine(LEAD_VARS_IMAGES_DIR, "Result.jpg"), RasterImageFormat.JPEG, 24); 
   System.out.println("Command run, image saved to " + combine(LEAD_VARS_IMAGES_DIR, "Result.jpg")); 
} 
Requirements

Target Platforms

See Also

Reference

WindowLevelCommand Members

Leadtools.ImageProcessing.Core Namespace

Introduction to Image Processing With LEADTOOLS

Manipulating Image Data

Grayscale Images

Leadtools.RasterPalette.WindowLevelFillLookupTable(Leadtools.RasterColor[],Leadtools.RasterColor,Leadtools.RasterColor,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,Leadtools.RasterPaletteWindowLevelFlags)

ApplyVoiLookupTableCommand Class

Leadtools.ImageProcessing.Color.ChannelMixerCommand

Leadtools.ImageProcessing.Effects.DeinterlaceCommand

Leadtools.ImageProcessing.Color.DesaturateCommand

Leadtools.ImageProcessing.Effects.EdgeDetectStatisticalCommand

Leadtools.ImageProcessing.Color.LightControlCommand

Leadtools.ImageProcessing.Effects.SmoothEdgesCommand

Leadtools.ImageProcessing.Color.LocalHistogramEqualizeCommand

Leadtools.ImageProcessing.Color.AddWeightedCommand

Leadtools.ImageProcessing.Color.ColorMergeCommand

Leadtools.ImageProcessing.Color.ColorSeparateCommand

Leadtools.ImageProcessing.Color.MultiplyCommand

Leadtools.ImageProcessing.Color.AutoColorLevelCommand

Leadtools.ImageProcessing.Color.ColorLevelCommand

CorrelationCommand Class

Leadtools.ImageProcessing.Color.GrayScaleToDuotoneCommand

Leadtools.ImageProcessing.Color.GrayScaleToMultitoneCommand

Leadtools.ImageProcessing.Effects.RegionHolesRemovalCommand

Leadtools.ImageProcessing.Color.SelectiveColorCommand

Leadtools.ImageProcessing.Effects.SkeletonCommand

Leadtools.ImageProcessing.Color.ChangeHueSaturationIntensityCommand

Leadtools.ImageProcessing.Color.ColorReplaceCommand

Leadtools.ImageProcessing.Color.ColorThresholdCommand

Leadtools.ImageProcessing.Color.MathematicalFunctionCommand

Leadtools.ImageProcessing.Color.SegmentCommand

Leadtools.ImageProcessing.Color.AdaptiveContrastCommand

Leadtools.ImageProcessing.Color.ApplyMathematicalLogicCommand

Leadtools.ImageProcessing.Color.ColorIntensityBalanceCommand

ColorizeGrayCommand Class

Leadtools.ImageProcessing.Color.ContrastBrightnessIntensityCommand

DigitalSubtractCommand Class

Leadtools.ImageProcessing.Color.DynamicBinaryCommand

Leadtools.ImageProcessing.Effects.EdgeDetectEffectCommand

Leadtools.ImageProcessing.SpecialEffects.FunctionalLightCommand

MultiscaleEnhancementCommand Class

SelectDataCommand Class

ShiftDataCommand Class

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

Leadtools.ImageProcessing.Core Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.