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




Colors an 8, 12 or 16-bit grayscale image. The class changes the color bits/pixel of the image from the specified formats into 24-bit RGB format. This class is available in the Raster Pro and above toolkits.

Object Model


Syntax

Visual Basic (Declaration) 
Public Class ColorizeGrayCommand 
   Inherits RasterCommand
   Implements IRasterCommand 
Visual Basic (Usage)Copy Code
Dim instance As ColorizeGrayCommand
C# 
public class ColorizeGrayCommand : RasterCommand, IRasterCommand  
Managed Extensions for C++ 
public __gc class ColorizeGrayCommand : public RasterCommand, IRasterCommand  
C++/CLI 
public ref class ColorizeGrayCommand : public RasterCommand, IRasterCommand  

Example

Visual BasicCopy Code
ImageProcessing.Core.ColorizeGrayCommand
   Public Sub ColorizeGrayCommandExample()
      RasterCodecs.Startup()
      Dim codecs As New RasterCodecs()
      codecs.ThrowExceptionsOnInvalidImages = True

      Dim leadImage As RasterImage = codecs.Load("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\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, "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\ColorizeGrayResult.Bmp", RasterImageFormat.Bmp, 24)

      RasterCodecs.Shutdown()
   End Sub
C#Copy Code
ImageProcessing.Core.ColorizeGrayCommand 
      public void ColorizeGrayCommandExample() 
      { 
         // Load an image 
 
         RasterCodecs.Startup(); 
         RasterCodecs codecs = new RasterCodecs(); 
         codecs.ThrowExceptionsOnInvalidImages = true; 
 
         RasterImage image = codecs.Load(@"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\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, @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\ColorizeGrayResult.Bmp", RasterImageFormat.Bmp, 24); 
 
         RasterCodecs.Shutdown(); 
      }

Remarks

  • The class can be used as a visualization aid. More precisely, this class can be used to show variations in an image's intensity values.
  • This class colors the grayscale image (colorizes) by converting specified ranges of grayscale intensities into corresponding RGB values. Use the GrayColors property to set the intensity ranges and the RGB values.
  • Using this class you can show details that were never seen in the original image. In 12 and 16-bit grayscale images, only the 8 most significant bits are displayed, whereas the rest are discarded. So by coloring these discarded bits you can make them visible instead.
  • The class will allocate and store a 24-bit image in DestinationImage.
  • If you set the GrayColors property to null then the class colors the image automatically using an algorithm that generates unique output colors. The output image will contain 256 colors if the input image is 8-bit, 4096 colors if the input image is 12-bit and 65535 colors if the input image is 16-bit.
  • The sample below shows you how to color a 16-bit grayscale image using the GrayColors property.
  • In a 16-bit grayscale image, the lowest pixel value is 0 and the highest pixel value is 65535.
  • The colors from the input images will be colored as follows:

    Pixel intensities from 0 - 9999 will be Red.
    Pixel intensities from 10000 - 19999 will be Green.
    Pixel intensities from 20000 - 29999 will be Blue.
    Pixel intensities from 30000 - 39999 will be Cyan.
    Pixel intensities from 40000 - 49999 will be Magenta.
    Pixel intensities from 50000 - 65535 will be Yellow. (Note: the Threshold value is ignored for the last entry in the GrayColors array.)
  • For more information on filling the GrayColors array to obtain this result, refer to the example.
  • This class supports 8, 12 and 16-bit grayscale images only. Support for 12 and 16-bit grayscale images are available only in the Document/Medical toolkits. It also can process the whole image or a region of the image. If an image has a region, the effect is applied only to the region.
  • This command does not support 32-bit grayscale images.
For more information, refer to Grayscale Images.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.RasterCommand
      Leadtools.ImageProcessing.Core.ColorizeGrayCommand

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