Leadtools.ImageProcessing.Color Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.10
RemapHueCommand Class
See Also  Members   Example 




Uses a lookup table to change an image's hue values. The saturation and value tables change S and V values only if a particular hue value is marked as non-zero in the Mask property. It is used for all resolutions, including 48 and 64-bit images.

Syntax

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

Example

Visual BasicCopy Code
ImageProcessing.Color.RemapHueCommandCommand
   Public Function INCREMENT_S1(ByVal x As Integer, ByVal Length As Integer) As Integer
      Return ((x + 1) Mod Length)
   End Function
   Public Function DECREMENT_S1(ByVal x As Integer, ByVal Length As Integer) As Integer
      Return ((x + (Length - 1)) Mod Length)
   End Function

   Public Function ADD_S1(ByVal x As Integer, ByVal y As Integer, ByVal Length As Integer) As Integer
      Return ((x + y) Mod Length)
   End Function


   Public Sub RemapHueCommandCommandExample()
      RasterCodecs.Startup()
      Dim codecs As New RasterCodecs()
      codecs.ThrowExceptionsOnInvalidImages = True

      Dim leadImage As RasterImage = codecs.Load("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Master.jpg")

      ' Prepare the command
      Dim MaskTable() As Integer
      Dim HueTable() As Integer
      Dim hsvRef As RasterHsvColor
      Dim HueGreen As Integer
      Dim HueChange As Integer

      Dim Change As Integer
      Dim i As Integer
      Dim Count As Integer
      Dim Length As Integer

      If (leadImage.BitsPerPixel >= 48) Then

         Length = 65536

      ElseIf (Not (leadImage.BitsPerPixel = 16 Or leadImage.BitsPerPixel = 12)) Then
         Length = 256
      ElseIf (IsNothing(leadImage.GetLookupTable) And leadImage.UseLookupTable) Then
         Length = 256
      Else
         Length = (1 << leadImage.BitsPerPixel)
      End If
      'Allocate tables
      ReDim MaskTable(Length - 1)
      ReDim HueTable(Length - 1)

      'Initialize tables
      For i = 0 To Length - 1
         MaskTable(i) = 0
         HueTable(i) = i
      Next

      'Get the hue for green
      hsvRef = RasterHsvColor.FromRasterColor(New RasterColor(0, 255, 0))

      HueGreen = hsvRef.H

      'Obtain new hue
      hsvRef = RasterHsvColor.FromRasterColor(New RasterColor(255, 128, 0))
      Change = hsvRef.H - HueGreen
      If (Change > 0) Then
         HueChange = Change
      Else
         HueChange = Change + Length - 1
      End If

      HueGreen = (HueGreen * (Length - 1)) \ 255
      HueChange = (HueChange * (Length - 1)) \ 255

      'Set values in HueTable, MaskTable
      HueTable(HueGreen) = HueTable(HueGreen) + HueChange
      MaskTable(HueGreen) = 1

      'set the hues near green (+/- 15)
      i = INCREMENT_S1(HueGreen, Length)

      For Count = (15 * (Length - 1)) \ 255 To 1 Step -1
         i = INCREMENT_S1(i, Length)
         HueTable(i) = ADD_S1(HueTable(i), HueChange, Length)
         MaskTable(i) = 1
      Next

      i = DECREMENT_S1(HueGreen, Length)

      For Count = (15 * (Length - 1)) \ 255 To 1 Step -1

         i = DECREMENT_S1(i, Length)
         HueTable(i) = ADD_S1(HueTable(i), HueChange, Length)
         MaskTable(i) = 1
      Next
      Dim command As RemapHueCommand = New RemapHueCommand(MaskTable, HueTable, Nothing, Nothing, Length)

      command.Run(leadImage)
      codecs.Save(leadImage, "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Result.jpg", RasterImageFormat.Jpeg, 24)

      RasterCodecs.Shutdown()
   End Sub
C#Copy Code
ImageProcessing.Color.RemapHueCommandCommand 
      public int INCREMENT_S1(int x, int Length) 
      { 
         return ((x + 1) % Length); 
      } 
      public int DECREMENT_S1(int x, int Length) 
      { 
         return ((x + (Length - 1)) % Length); 
      } 
 
      public int ADD_S1(int x, int y, int Length) 
      { 
         return ((x + y) % Length); 
      } 
 
 
      public void RemapHueCommandCommandExample() 
      { 
         // Load an image 
         RasterCodecs.Startup(); 
         RasterCodecs codecs = new RasterCodecs(); 
         codecs.ThrowExceptionsOnInvalidImages = true; 
 
         RasterImage image = codecs.Load(@"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Master.jpg"); 
 
         // Prepare the command 
         int[]  MaskTable; 
         int[]  HueTable; 
         RasterHsvColor hsvRef; 
         int    HueGreen, HueChange; 
         int    Change; 
         int    i, Count; 
         int    Length; 
 
         if(image.BitsPerPixel >= 48) 
            Length = 0x10000; 
         else if(!(image.BitsPerPixel == 16 || image.BitsPerPixel == 12)) 
            Length = 256; 
         else if(image.GetLookupTable() != null && image.UseLookupTable) 
            Length = 256; 
         else 
            Length = (1 << image.BitsPerPixel); 
 
         //Allocate tables 
         MaskTable = new int[Length]; 
         HueTable  = new int[Length]; 
 
         //Initialize tables 
         for (i = 0; i < Length; i++) 
         { 
            MaskTable[i] = 0; 
            HueTable[i] = i; 
         } 
 
         //Get the hue for green 
         hsvRef = RasterHsvColor.FromRasterColor(new RasterColor(0,255,0)); 
 
         HueGreen = hsvRef.H; 
 
         //Obtain new hue   
         hsvRef =  RasterHsvColor.FromRasterColor(new RasterColor(255, 128, 0)); 
         Change = (int)hsvRef.H - (int)HueGreen; 
         HueChange = (Change>0) ? (int)Change : (int)(Change + Length - 1); 
         HueGreen   *= (Length - 1)/255; 
         HueChange *= (Length - 1)/255; 
 
         //Set values in HueTable, MaskTable  
         HueTable[HueGreen] = (HueTable[HueGreen] + HueChange); 
         MaskTable[HueGreen] = 1; 
 
         //set the hues near green (+/- 15) 
         Count = (15 * (Length - 1))/255; 
         for (i = INCREMENT_S1(HueGreen, Length); Count > 0; i = INCREMENT_S1(i, Length), Count--) 
         { 
            HueTable[i] = ADD_S1(HueTable[i], HueChange, Length); 
            MaskTable[i] = 1; 
         } 
 
         Count = (15 * (Length - 1))/255; 
         for (i = DECREMENT_S1(HueGreen, Length); Count > 0; i = DECREMENT_S1(i, Length), Count--) 
         { 
            HueTable[i] = ADD_S1(HueTable[i], HueChange, Length); 
            MaskTable[i] = 1; 
         } 
 
         RemapHueCommand command = new RemapHueCommand(MaskTable, HueTable, null, null, Length); 
         command.Run(image); 
         codecs.Save(image, @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Result.jpg", RasterImageFormat.Jpeg, 24); 
 
         RasterCodecs.Shutdown(); 
      }

Remarks

  • This command can be used to change a range of colors to another range of colors. For example, it could be used to change all red pixels to any color, where a red pixel can have any brightness (V) and any amount of white (saturation). A red pixel in this case would be RGB(x,y,y) where 0 <= x <(LookUpTableLength - 1) and 0 <= y < x or in the HSV color space HSV(0,x,x) where 0<=x<=(LookUpTableLength - 1)
  • The Mask lookup table identifies which values in the HueTable are valid. If a Mask value is 0, then the corresponding value in the HueTable is ignored. If a Mask value is non-zero, then the corresponding value in the HueTable is used. For example, if a pixel has a hue value of 240 and Mask[240] is nonzero, then the hue value of 240 is replaced with HueTable[240]. Traditionally, hue ranges from 0 to 359. For the lookup table, the range of 0 to 359 is remapped to a range of 0.. LookUpTableLength - 1. For example, if LookUpTableLength = 256
  • This command supports 48 and 64-bit colored images.
  • This command does not support signed data images.
  • This command does not support 32-bit grayscale images.
For more information, refer to Changing Brightness and Contrast.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.RasterCommand
      Leadtools.ImageProcessing.Color.RemapHueCommand

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