Leadtools.ImageProcessing.Core Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
ColorizeGrayCommandData Class
See Also  Members   Example 
Leadtools.ImageProcessing.Core Namespace : ColorizeGrayCommandData Class



The ColorizeGrayCommandData class contains information about gray color intensities (Threshold) and the associated colors (Color) used in the coloration methods of the ColorizeGrayCommand class.

Syntax

Visual Basic (Declaration) 
Public Class ColorizeGrayCommandData 
Visual Basic (Usage)Copy Code
Dim instance As ColorizeGrayCommandData
C# 
public class ColorizeGrayCommandData 
C++/CLI 
public ref class ColorizeGrayCommandData 

Example

This example loads a 16-bit grayscale image and then colors it.

Visual BasicCopy Code
Public Sub ColorizeGrayCommandDataExample()
   RasterCodecs.Startup()
   Dim codecs As New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True

   Dim leadImage As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Beauty16.jpg")

   ' Prepare the command
   Dim i As Integer
   Dim pGrayColors() As ColorizeGrayCommandData
   ReDim pGrayColors(5)

   For i = 0 To 5
      pGrayColors(i) = New ColorizeGrayCommandData
   Next

   pGrayColors(0).Threshold = 9999
   pGrayColors(1).Threshold = 19999
   pGrayColors(2).Threshold = 29999
   pGrayColors(3).Threshold = 39999
   pGrayColors(4).Threshold = 49999
   pGrayColors(5).Threshold = 59999

   pGrayColors(0).Color = New RasterColor(255, 0, 0)
   pGrayColors(1).Color = New RasterColor(0, 255, 0)
   pGrayColors(2).Color = New RasterColor(0, 0, 255)
   pGrayColors(3).Color = New RasterColor(0, 255, 255)
   pGrayColors(4).Color = New RasterColor(255, 0, 255)
   pGrayColors(5).Color = New RasterColor(255, 255, 0)

   Dim command As ColorizeGrayCommand = New ColorizeGrayCommand
   command.GrayColors = pGrayColors
   'Call the command
   command.Run(leadImage)

   ' Save the resulted Image
   codecs.Save(command.DestinationImage, LeadtoolsExamples.Common.ImagesPath.Path + "ColorizeGrayResult.Bmp", RasterImageFormat.Bmp, 24)

   RasterCodecs.Shutdown()
End Sub
C#Copy Code
public void ColorizeGrayCommandDataExample() 

   // Load an image 
   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Beauty16.jpg"); 
 
   // Prepare the command 
   ColorizeGrayCommandData[] pGrayColors = new ColorizeGrayCommandData[6]; 
   for (int i = 0; i < 6; i++) 
      pGrayColors[i] = new ColorizeGrayCommandData(); 
   pGrayColors[0].Threshold   = 9999; 
   pGrayColors[1].Threshold   = 19999; 
   pGrayColors[2].Threshold   = 29999; 
   pGrayColors[3].Threshold   = 39999; 
   pGrayColors[4].Threshold   = 49999; 
   pGrayColors[5].Threshold   = 59999; 
 
   pGrayColors[0].Color       = new RasterColor(255, 0, 0); 
   pGrayColors[1].Color       = new RasterColor(0, 255, 0); 
   pGrayColors[2].Color       = new RasterColor(0, 0, 255); 
   pGrayColors[3].Color       = new RasterColor(0, 255, 255); 
   pGrayColors[4].Color       = new RasterColor(255, 0, 255); 
   pGrayColors[5].Color       = new RasterColor(255, 255, 0); 
 
   ColorizeGrayCommand command = new ColorizeGrayCommand(); 
   command.GrayColors = pGrayColors; 
   //Call the command 
   command.Run(image); 
 
   // Save the resulted image 
   codecs.Save(command.DestinationImage, LeadtoolsExamples.Common.ImagesPath.Path + "ColorizeGrayResult.Bmp", RasterImageFormat.Bmp, 24); 
 
   RasterCodecs.Shutdown(); 
}

Remarks

  • The ColorizeGrayCommand class uses an array of ColorizeGrayCommand class objects with its length being a user-defined number. If the array has N entries, then:
    Intensity RangeColor
    0 ~ Threshold[0]Color[0]
    Threshold[0] ~ Threshold[1]Color[1]
    Threshold[1] ~ Threshold[2]Color[2]
    ......
    Threshold[N - 3] ~ Threshold[N - 2]Color[N - 2]
    Threshold[N - 2] ~ Threshold[N - 1]Color[N - 1]
  • Notice that the Threshold[N-1] value will be ignored and instead will be treated as a value equal to 255, 4095 and 65535 for 8, 12 and 16-bit images respectively.
  • Although it is not a requirement, it is recommended that Threshold[0] is less than Threshold[1], which is less than Threshold[2], ..., which is less than Threshold[N-1]. Consider the following example with a ColorizeGrayCommandData class of 4 entries for a 12-Bit gray image, where this recommendation is not followed:
    Threshold[0] = 1000Color[0] is Red
    Threshold[1] = 3000Color[1] is Green
    Threshold[2] = 2000 // Notice the threshold here. Color[2] is Blue
    Threshold[3] = 4000Color[3] is Yellow
  • In this case, pixel intensities from 0 to 1000 will be Red, pixels 1001 to 3000 will be Green, pixels 3001 to 4000 will be Yellow, and pixels from 4001 to the last possible intensity will be Yellow too.

For more information, refer to Correcting Colors.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.Core.ColorizeGrayCommandData

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also