WindowLevel Method (original) (raw)
Summary
Sets up the paint or paint and image processing methods' window leveling options for this RasterImage
Syntax
C#
Objective-C
C++/CLI
Java
Python
- (BOOL)windowLevel:(NSInteger)_lowBit_Value
highBit:(NSInteger)_highBit_Value
palette:(nullable NSArray<LTRasterColor *> *)_palette_
mode:(LTRasterWindowLevelMode)_mode_
error:(NSError **)error
def WindowLevel(self,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, the conversion is a normal shift (right or left) and the painted image is 8-bit grayscale. If palette is not null, 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.
Example
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 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:\LEADTOOLS22\Resources\Images";
}
Leadtools Assembly