←Select platform

SetLookupTable Method

Summary
Sets the 8-bit lookup table (LUT) of this RasterImage.
Syntax
C#
VB
Objective-C
C++
Java
public void SetLookupTable( 
   RasterColor[] value 
) 
Public Sub SetLookupTable( _ 
   ByVal value() As RasterColor _ 
)  
- (BOOL)setLookupTable:(nullable NSArray<LTRasterColor *> *)lut error:(NSError **)error 
public void setLookupTable(RasterColor[] value) 
public: 
void SetLookupTable(  
   array<RasterColor>^ value 
)  

Parameters

value
An array of RasterColor structures which represent the lookup table (LUT) of this RasterImage.

Remarks

The lookup table (LUT) is used when the value of UseLookupTable is set to true.

The 8-bit and 16-bit lookup tables are synchronized, so when you change one, the other is changed as well The 16-bit lookup table (SetLookupTable16) has more precision so it is recommended you use the 16-bit LUT instead of the 8-bit LUT.

LUT is only used for 10-16 bit extended grayscale image or 10-16 bit palette color image. To update the palette in 1-8 bit image use SetPalette. For more information, refer to Grayscale Images.

LUT is also used for displaying extended Palette color image such as bit stored is 16-bit and LUT contains color value. This is typical of Ultra Sound image.

Example
C#
VB
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 SetLookupTable() 
{ 
	DicomEngine.Startup(); 
 
	// Create a RasterCodecs class for saving out images 
	RasterCodecs codecs = new RasterCodecs(); 
 
	// Load a dataset 
	DicomDataSet ds = new DicomDataSet(); 
	ds.Load(Path.Combine(LEAD_VARS.ImagesDir, "DICOM","image3.dcm"), DicomDataSetLoadFlags.None); 
 
	// Get the image but do NOT auto-apply any of the LUTs 
	DicomElement element = ds.FindFirstElement(null, DicomTag.PixelData, true); 
	RasterImage image = ds.GetImage(element, 0, 16, RasterByteOrder.Gray, DicomGetImageFlags.None); 
	image.UseLookupTable = true; 
 
	// Save out the image without any LUTs applied.  It should be black 
	codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "BeforeSetLookupTable.bmp"), RasterImageFormat.Bmp, 8); 
 
	// Create a LUT 
	RasterColor[] lut = new RasterColor[(int)Math.Pow(2, 16)]; 
 
	// Get the Minimum and Maximum values so we can calculate appropriate LUT values. 
	MinMaxValuesCommand cmdMinMax = new MinMaxValuesCommand(); 
	cmdMinMax.Run(image); 
	int maxVal = cmdMinMax.MaximumValue; 
	int minVal = cmdMinMax.MinimumValue; 
 
	for (int i = 0; i < lut.Length; i++) 
	{ 
		lut[i].R = Convert.ToByte(Math.Min(255, ((i - minVal) * 255 / (maxVal - minVal)))); 
		lut[i].G = lut[i].R; 
		lut[i].B = lut[i].R; 
	} 
 
	// Set the new lookup table 
	image.SetLookupTable(lut); 
 
	// Save out the image with the LUT applied.  It should look normal 
	codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir,"DICOM", "AfterSetLookupTable.bmp"), RasterImageFormat.Bmp, 8); 
 
	DicomEngine.Shutdown(); 
} 
 
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 
 
Private Sub SetLookupTable() 
   DicomEngine.Startup() 
 
   ' Get the path of the LEADTOOLS images directory 
   Dim strImagesDirectory As String = "C:\LEADTOOLS21\Resources\Images\DICOM" 
 
   ' Create a RasterCodecs class for saving out images 
   Dim codecs As RasterCodecs = New RasterCodecs() 
 
   ' Load a dataset 
   Dim ds As DicomDataSet = New DicomDataSet() 
   ds.Load(strImagesDirectory & "IMAGE3.dcm", DicomDataSetLoadFlags.None) 
 
   ' Get the image but do NOT auto-apply any of the LUTs 
   Dim element As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PixelData, True) 
   Dim image As RasterImage = ds.GetImage(element, 0, 16, RasterByteOrder.Gray, DicomGetImageFlags.None) 
   image.UseLookupTable = True 
 
   ' Save out the image without any LUTs applied.  It should be black 
   codecs.Save(image, strImagesDirectory & "BeforeSetLookupTable.bmp", RasterImageFormat.Bmp, 8) 
 
   ' Create a LUT 
   Dim lut As RasterColor() = New RasterColor(CInt(Math.Pow(2, 16)) - 1) {} 
 
   ' Get the Minimum and Maximum values so we can calculate appropriate LUT values. 
   Dim cmdMinMax As MinMaxValuesCommand = New MinMaxValuesCommand() 
   cmdMinMax.Run(image) 
   Dim maxVal As Integer = cmdMinMax.MaximumValue 
   Dim minVal As Integer = cmdMinMax.MinimumValue 
 
   Dim i As Integer = 0 
   Do While i < lut.Length 
      lut(i).R = Convert.ToByte(Math.Min(255, ((i - minVal) * 255 / (maxVal - minVal)))) 
      lut(i).G = lut(i).R 
      lut(i).B = lut(i).R 
      i += 1 
   Loop 
 
   ' Set the new lookup table 
   image.SetLookupTable(lut) 
 
   ' Save out the image with the LUT applied.  It should look normal 
   codecs.Save(image, strImagesDirectory & "AfterSetLookupTable.bmp", RasterImageFormat.Bmp, 8) 
 
   DicomEngine.Shutdown() 
End Sub 
Requirements

Target Platforms

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

Leadtools Assembly

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