WindowLevel example for Delphi
These 3 examples convert a bitmap to 12-bit grayscale and then perform window leveling on the four most significant bits of the image.
Ex1.
var
RasterProc: LEADRasterProcess;
sRet: smallint;
begin
RasterProc:= CreateComObject (CLASS_LEADRasterProcess) as LEADRasterProcess;
//WindowLevel for Display
RasterProc.Grayscale (LEADRasterView1.Raster, 12); //Grayscale image to 12-bit
LEADRasterView1.Raster.LevelLowBit:= 8 ;//use 4 most significant bits
LEADRasterView1.Raster.LevelHighBit:= 11;
LEADRasterView1.WindowLevel (sRet);
end;
Ex2.
Var
RasterProc: LEADRasterProcess;
begin
RasterProc:= CreateComObject (CLASS_LEADRasterProcess) as LEADRasterProcess;
//WindowLevel image processing
RasterProc.Grayscale ( LEADRasterView1.Raster, 12 ); //Grayscale image to 12-bit
LEADRasterView1.Raster.LevelLowBit:= 8 ;// use 4 most significant bits
LEADRasterView1.Raster.LevelHighBit:= 11 ;
RasterProc.WindowLevel ( LEADRasterView1.Raster ) ;
end;
Ex3.
//This example loads a 16-bit grayscale, fills the window level lookup table,
// and window levels the bitmap for display only
var
i: Longint;
RasterProc: LEADRasterProcess;
RasterIO: LEADRasterIO;
sRet: smallint;
begin
RasterProc:= CreateComObject (CLASS_LEADRasterProcess) as LEADRasterProcess;
RasterIO:= CreateComObject (CLASS_LEADRasterIO) as LEADRasterIO;
//Load a 16-bit grayscale image
RasterIO.Load ( LEADRasterView1.Raster, 'v:\images\image5.dic', 0, 0, 1) ;
LEADRasterView1.AutoRepaint := False;
//Use all bits
LEADRasterView1.Raster.LevelLowBit := 0;
LEADRasterView1.Raster.LevelHighBit := LEADRasterView1.Raster.BitmapBits - 1;
LEADRasterView1.Raster.GetMinMaxBits ( ) ;
LEADRasterView1.Raster.GetMinMaxVal ( ) ;
//Set LUT so the range is from pure blue to pure red
for i := LEADRasterView1.Raster.MinVal to LEADRasterView1.Raster.MaxVal do
LEADRasterView1.Raster.LevelLUT [i]:= RGB((i Mod 256), 0, 256 - (i Mod 256));
//Window level for display only--leave the bitmap data unchanged
LEADRasterView1.WindowLevel (sRet);
LEADRasterView1.ForceRepaint (sRet);
end;