LEADTOOLS Image Processing (Leadtools.ImageProcessing.Color assembly)
LEAD Technologies, Inc

RemapHueCommand Constructor()

Example 





Initializes a new RemapHueCommand class object with default parameters. .NET support Silverlight support
Syntax
public RemapHueCommand()
'Declaration
 
Public Function New()
'Usage
 
Dim instance As New RemapHueCommand()
public RemapHueCommand()
function RemapHueCommand()
public:
RemapHueCommand();
Example
 
Public Function INCREMENT_S2(ByVal x As Integer, ByVal Length As Integer) As Integer
   Return ((x + 1) Mod Length)
End Function
Public Function DECREMENT_S2(ByVal x As Integer, ByVal Length As Integer) As Integer
   Return ((x + (Length - 1)) Mod Length)
End Function

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

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

   Dim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Master.jpg"))

   ' Prepare the command
   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

   Dim MaskTable() As Integer
   Dim HueTable() As Integer
   'Allocate tables
   ReDim MaskTable(Length - 1)
   ReDim HueTable(Length - 1)

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

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

   Dim HueGreen As Integer
   HueGreen = hsvRef.H

   'Obtain new hue  
   hsvRef = RasterHsvColor.FromRasterColor(New RasterColor(255, 128, 0))
   Dim Change As Integer = hsvRef.H - HueGreen
   Dim HueChange As Integer
   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_S2(HueGreen, Length)

   Dim Count As Integer
   For Count = (15 * (Length - 1)) \ 255 To 1 Step -1
      i = INCREMENT_S2(i, Length)
      HueTable(i) = ADD_S2(HueTable(i), HueChange, Length)
      MaskTable(i) = 1
   Next

   i = DECREMENT_S2(HueGreen, Length)

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

      i = DECREMENT_S2(i, Length)
      HueTable(i) = ADD_S2(HueTable(i), HueChange, Length)
      MaskTable(i) = 1
   Next
   Dim command As RemapHueCommand = New RemapHueCommand
   command.Mask = MaskTable
   command.HueTable = HueTable
   command.SaturationTable = Nothing
   command.ValueTable = Nothing
   command.LookUpTableLength = Length

   command.Run(leadImage)
   codecs.Save(leadImage, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24)

End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public int INCREMENT_S2(int x, int Length)
   {
      return ((x+1)% Length);
   }
   public int DECREMENT_S2(int x, int Length)
   {
      return (( x + (Length - 1)) % Length);
   }

   public int ADD_S2(int x,int y, int Length)
   {
      return ((x+y)% Length);
   }

   public void RemapHueCommandConstructorExample()
   {
      // Load an image
      RasterCodecs codecs = new RasterCodecs();
      codecs.ThrowExceptionsOnInvalidImages = true;

      RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Master.jpg"));

      // Prepare the command
      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
      int[] MaskTable = new int[Length];
      int[] HueTable  = new int[Length];

      //Initialize tables
      for (int i = 0; i < Length; i++)
      {
         MaskTable[i] = 0;
         HueTable[i] = i;
      }

      //Get the hue for green
      RasterHsvColor hsvRef = RasterHsvColor.FromRasterColor(new RasterColor(0,255,0));

      int HueGreen = hsvRef.H;

      //Obtain new hue  
      hsvRef =  RasterHsvColor.FromRasterColor(new RasterColor(255, 128, 0));
      int Change = (int)hsvRef.H - (int)HueGreen;
      int 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)
      int Count = (15 * (Length - 1))/255;
      for (int i = INCREMENT_S2(HueGreen, Length); Count > 0; i = INCREMENT_S2(i, Length), Count--)
      {
         HueTable[i] = ADD_S2(HueTable[i], HueChange, Length);
         MaskTable[i] = 1;
      }

      Count = (15 * (Length - 1)) / 255;
      for (int i = DECREMENT_S2(HueGreen, Length); Count > 0; i = DECREMENT_S2(i, Length), Count--)
      {
         HueTable[i] = ADD_S2(HueTable[i], HueChange, Length);
         MaskTable[i] = 1;
      }

      RemapHueCommand command = new RemapHueCommand();
      command.Mask = MaskTable;
      command.HueTable = HueTable;
      command.SaturationTable = null;
      command.ValueTable = null;
      command.LookUpTableLength = Length;
      command.Run(image);
      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24);

   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
public int INCREMENT_S2(int x, int Length)
{
   return ((x+1)% Length);
}
public int DECREMENT_S2(int x, int Length)
{
   return (( x + (Length - 1)) % Length);
}

public int ADD_S2(int x,int y, int Length)
{
   return ((x+y)% Length);
}
[TestMethod]
public async Task RemapHueCommandConstructorExample()
{
   // Load an image
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;

   // Load the image
   string srcFileName = @"Assets\Image1.cmp";
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   // Prepare the command
   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
   int[] MaskTable = new int[Length];
   int[] HueTable  = new int[Length];

   //Initialize tables
   for (int i = 0; i < Length; i++)
   {
      MaskTable[i] = 0;
      HueTable[i] = i;
   }

   //Get the hue for green
   RasterHsvColor hsvRef = RasterHsvColorHelper.FromRasterColor(RasterColorHelper.Create(0,255,0));

   int HueGreen = hsvRef.H;

   //Obtain new hue  
   hsvRef =  RasterHsvColorHelper.FromRasterColor(RasterColorHelper.Create(255, 128, 0));
   int Change = (int)hsvRef.H - (int)HueGreen;
   int 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)
   int Count = (15 * (Length - 1))/255;
   for (int i = INCREMENT_S2(HueGreen, Length); Count > 0; i = INCREMENT_S2(i, Length), Count--)
   {
      HueTable[i] = ADD_S2(HueTable[i], HueChange, Length);
      MaskTable[i] = 1;
   }

   Count = (15 * (Length - 1)) / 255;
   for (int i = DECREMENT_S2(HueGreen, Length); Count > 0; i = DECREMENT_S2(i, Length), Count--)
   {
      HueTable[i] = ADD_S2(HueTable[i], HueChange, Length);
      MaskTable[i] = 1;
   }

   RemapHueCommand command = new RemapHueCommand();
   command.Mask = MaskTable;
   command.HueTable = HueTable;
   command.SaturationTable = null;
   command.ValueTable = null;
   command.LookUpTableLength = Length;
   command.Run(image);

   string destFileName = @"result.jpg";
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Jpeg, 0);
}
public int INCREMENT_S2(int x, int Length)
{
   return ((x+1)% Length);
}
public int DECREMENT_S2(int x, int Length)
{
   return (( x + (Length - 1)) % Length);
}

public int ADD_S2(int x,int y, int Length)
{
   return ((x+y)% Length);
}
public void RemapHueCommandConstructorExample(RasterImage image, Stream outStream)
{
   // Prepare the command
   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
   int[] MaskTable = new int[Length];
   int[] HueTable  = new int[Length];

   //Initialize tables
   for (int i = 0; i < Length; i++)
   {
      MaskTable[i] = 0;
      HueTable[i] = i;
   }

   //Get the hue for green
   RasterHsvColor hsvRef = RasterHsvColor.FromRasterColor(new RasterColor(0,255,0));

   int HueGreen = hsvRef.H;

   //Obtain new hue  
   hsvRef =  RasterHsvColor.FromRasterColor(new RasterColor(255, 128, 0));
   int Change = (int)hsvRef.H - (int)HueGreen;
   int 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)
   int Count = (15 * (Length - 1))/255;
   for (int i = INCREMENT_S2(HueGreen, Length); Count > 0; i = INCREMENT_S2(i, Length), Count--)
   {
      HueTable[i] = ADD_S2(HueTable[i], HueChange, Length);
      MaskTable[i] = 1;
   }

   Count = (15 * (Length - 1)) / 255;
   for (int i = DECREMENT_S2(HueGreen, Length); Count > 0; i = DECREMENT_S2(i, Length), Count--)
   {
      HueTable[i] = ADD_S2(HueTable[i], HueChange, Length);
      MaskTable[i] = 1;
   }

   RemapHueCommand command = new RemapHueCommand();
   command.Mask = MaskTable;
   command.HueTable = HueTable;
   command.SaturationTable = null;
   command.ValueTable = null;
   command.LookUpTableLength = Length;
   command.Run(image);

   // Save result image
   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24);
   image.Dispose();
}
Public Function INCREMENT_S2(ByVal x As Integer, ByVal Length As Integer) As Integer
   Return ((x+1) Mod Length)
End Function
Public Function DECREMENT_S2(ByVal x As Integer, ByVal Length As Integer) As Integer
   Return ((x + (Length - 1)) Mod Length)
End Function

Public Function ADD_S2(ByVal x As Integer, ByVal y As Integer, ByVal Length As Integer) As Integer
   Return ((x+y) Mod Length)
End Function
Public Sub RemapHueCommandConstructorExample(ByVal image As RasterImage, ByVal outStream As Stream)
   ' Prepare the command
   Dim Length As Integer
   If image.BitsPerPixel >= 48 Then
      Length = &H10000
   Else If Not(image.BitsPerPixel = 16 OrElse image.BitsPerPixel = 12) Then
      Length = 256
   Else If Not image.GetLookupTable() Is Nothing AndAlso image.UseLookupTable Then
      Length = 256
   Else
      Length = (1 << image.BitsPerPixel)
   End If

   'Allocate tables
   Dim MaskTable As Integer() = New Integer(Length - 1){}
   Dim HueTable As Integer() = New Integer(Length - 1){}

   'Initialize tables
   Dim i As Integer = 0
   Do While i < Length
      MaskTable(i) = 0
      HueTable(i) = i
      i += 1
   Loop

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

   Dim HueGreen As Integer = hsvRef.H

   'Obtain new hue  
   hsvRef = RasterHsvColor.FromRasterColor(New RasterColor(255, 128, 0))
   Dim Change As Integer = CInt(hsvRef.H) - CInt(HueGreen)
   Dim HueChange As Integer
   If (Change>0) Then
      HueChange = CInt(Change)
   Else
      HueChange = CInt(Change + Length - 1)
   End If
   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)
   Dim Count As Integer = (15 * (Length - 1))/255
   i = INCREMENT_S2(HueGreen, Length)
   Do While Count > 0
      HueTable(i) = ADD_S2(HueTable(i), HueChange, Length)
      MaskTable(i) = 1
      i = INCREMENT_S2(i, Length)
      Count -= 1
   Loop

   Count = (15 * (Length - 1)) / 255
   i = DECREMENT_S2(HueGreen, Length)
   Do While Count > 0
      HueTable(i) = ADD_S2(HueTable(i), HueChange, Length)
      MaskTable(i) = 1
      i = DECREMENT_S2(i, Length)
      Count -= 1
   Loop

   Dim command As RemapHueCommand = New RemapHueCommand()
   command.Mask = MaskTable
   command.HueTable = HueTable
   command.SaturationTable = Nothing
   command.ValueTable = Nothing
   command.LookUpTableLength = Length
   command.Run(image)

   ' Save result image
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24)
   image.Dispose()
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

RemapHueCommand Class
RemapHueCommand Members
Overload List

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.