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.
public class RemapHueCommand : Leadtools.Imageprocessing.Leadtools.ImageProcessing.RasterCommand, Leadtools.Imageprocessing.Leadtools.ImageProcessing.IRasterCommandPublic Class RemapHueCommandInherits Leadtools.Imageprocessing.Leadtools.ImageProcessing.RasterCommandImplements Leadtools.Imageprocessing.Leadtools.ImageProcessing.IRasterCommand
public sealed class RemapHueCommand : Leadtools.Imageprocessing.Leadtools.ImageProcessing.IRasterCommand@interface LTRemapHueCommand : LTRasterCommandpublic class RemapHueCommand extends RasterCommandfunction Leadtools.ImageProcessing.Color.RemapHueCommand()public ref class RemapHueCommand : public Leadtools.Imageprocessing.Leadtools.ImageProcessing.RasterCommand, Leadtools.Imageprocessing.Leadtools.ImageProcessing.IRasterCommandFor more information, refer to Changing Brightness and Contrast.
Run the RemapHueCommand on an image and change all green hues (and hues near green).
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessing.ColorPublic Function INCREMENT_S1(ByVal x As Integer, ByVal Length As Integer) As IntegerReturn ((x + 1) Mod Length)End FunctionPublic Function DECREMENT_S1(ByVal x As Integer, ByVal Length As Integer) As IntegerReturn ((x + (Length - 1)) Mod Length)End FunctionPublic Function ADD_S1(ByVal x As Integer, ByVal y As Integer, ByVal Length As Integer) As IntegerReturn ((x + y) Mod Length)End FunctionPublic Sub RemapHueCommandCommandExample()Dim codecs As New RasterCodecs()codecs.ThrowExceptionsOnInvalidImages = TrueDim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg"))' Prepare the commandDim MaskTable() As IntegerDim HueTable() As IntegerDim hsvRef As RasterHsvColorDim HueGreen As IntegerDim HueChange As IntegerDim Change As IntegerDim i As IntegerDim Count As IntegerDim Length As IntegerIf (leadImage.BitsPerPixel >= 48) ThenLength = 65536ElseIf (Not (leadImage.BitsPerPixel = 16 Or leadImage.BitsPerPixel = 12)) ThenLength = 256ElseIf (IsNothing(leadImage.GetLookupTable) And leadImage.UseLookupTable) ThenLength = 256ElseLength = (1 << leadImage.BitsPerPixel)End If'Allocate tablesReDim MaskTable(Length - 1)ReDim HueTable(Length - 1)'Initialize tablesFor i = 0 To Length - 1MaskTable(i) = 0HueTable(i) = iNext'Get the hue for greenhsvRef = RasterHsvColor.FromRasterColor(New RasterColor(0, 255, 0))HueGreen = hsvRef.H'Obtain new huehsvRef = RasterHsvColor.FromRasterColor(New RasterColor(255, 128, 0))Change = hsvRef.H - HueGreenIf (Change > 0) ThenHueChange = ChangeElseHueChange = Change + Length - 1End IfHueGreen = (HueGreen * (Length - 1)) \ 255HueChange = (HueChange * (Length - 1)) \ 255'Set values in HueTable, MaskTableHueTable(HueGreen) = HueTable(HueGreen) + HueChangeMaskTable(HueGreen) = 1'set the hues near green (+/- 15)i = INCREMENT_S1(HueGreen, Length)For Count = (15 * (Length - 1)) \ 255 To 1 Step -1i = INCREMENT_S1(i, Length)HueTable(i) = ADD_S1(HueTable(i), HueChange, Length)MaskTable(i) = 1Nexti = DECREMENT_S1(HueGreen, Length)For Count = (15 * (Length - 1)) \ 255 To 1 Step -1i = DECREMENT_S1(i, Length)HueTable(i) = ADD_S1(HueTable(i), HueChange, Length)MaskTable(i) = 1NextDim command As RemapHueCommand = New RemapHueCommand(MaskTable, HueTable, Nothing, Nothing, Length)command.Run(leadImage)codecs.Save(leadImage, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24)End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing.Color;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 imageRasterCodecs codecs = new RasterCodecs();codecs.ThrowExceptionsOnInvalidImages = true;RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg"));// Prepare the commandint[] 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;elseLength = (1 << image.BitsPerPixel);//Allocate tablesMaskTable = new int[Length];HueTable = new int[Length];//Initialize tablesfor (i = 0; i < Length; i++){MaskTable[i] = 0;HueTable[i] = i;}//Get the hue for greenhsvRef = RasterHsvColor.FromRasterColor(new RasterColor(0,255,0));HueGreen = hsvRef.H;//Obtain new huehsvRef = 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, MaskTableHueTable[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, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24);}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing.Color;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 async Task RemapHueCommandCommandExample(){// Load an imageRasterCodecs codecs = new RasterCodecs();codecs.ThrowExceptionsOnInvalidImages = true;// Load the imagestring srcFileName = @"Assets\Image1.cmp";StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));// Prepare the commandint[] 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;elseLength = (1 << image.BitsPerPixel);//Allocate tablesMaskTable = new int[Length];HueTable = new int[Length];//Initialize tablesfor (i = 0; i < Length; i++){MaskTable[i] = 0;HueTable[i] = i;}//Get the hue for greenhsvRef = RasterHsvColorHelper.FromRasterColor(RasterColorHelper.Create(0,255,0));HueGreen = hsvRef.H;//Obtain new huehsvRef = RasterHsvColorHelper.FromRasterColor(RasterColorHelper.Create(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, MaskTableHueTable[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);string destFileName = @"result.jpg";StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Jpeg, 0);}
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing.Color;using Leadtools.Examples;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(RasterImage image, Stream outStream){// Prepare the commandint[] 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;elseLength = (1 << image.BitsPerPixel);//Allocate tablesMaskTable = new int[Length];HueTable = new int[Length];//Initialize tablesfor (i = 0; i < Length; i++){MaskTable[i] = 0;HueTable[i] = i;}//Get the hue for greenhsvRef = RasterHsvColor.FromRasterColor(new RasterColor(0,255,0));HueGreen = hsvRef.H;//Obtain new huehsvRef = RasterHsvColor.FromRasterColor(new RasterColor(255, 128, 0));Change = hsvRef.H - HueGreen;HueChange = (Change>0) ? Change : (Change + Length - 1);HueGreen *= (Length - 1)/255;HueChange *= (Length - 1)/255;//Set values in HueTable, MaskTableHueTable[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((int)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);// Save result imageRasterCodecs codecs = new RasterCodecs();codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24);image.Dispose();}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessing.ColorPublic Function INCREMENT_S1(ByVal x As Integer, ByVal Length As Integer) As IntegerReturn ((x + 1) Mod Length)End FunctionPublic Function DECREMENT_S1(ByVal x As Integer, ByVal Length As Integer) As IntegerReturn ((x + (Length - 1)) Mod Length)End FunctionPublic Function ADD_S1(ByVal x As Integer, ByVal y As Integer, ByVal Length As Integer) As IntegerReturn ((x + y) Mod Length)End FunctionPublic Sub RemapHueCommandCommandExample(ByVal image As RasterImage, ByVal outStream As Stream)' Prepare the commandDim MaskTable As Integer()Dim HueTable As Integer()Dim hsvRef As RasterHsvColorDim HueGreen, HueChange As IntegerDim Change As IntegerDim i, Count As IntegerDim Length As IntegerIf image.BitsPerPixel >= 48 ThenLength = &H10000Else If Not(image.BitsPerPixel = 16 OrElse image.BitsPerPixel = 12) ThenLength = 256Else If Not image.GetLookupTable() Is Nothing AndAlso image.UseLookupTable ThenLength = 256ElseLength = (1 << image.BitsPerPixel)End If'Allocate tablesMaskTable = New Integer(Length - 1){}HueTable = New Integer(Length - 1){}'Initialize tablesi = 0Do While i < LengthMaskTable(i) = 0HueTable(i) = ii += 1Loop'Get the hue for greenhsvRef = RasterHsvColor.FromRasterColor(New RasterColor(0,255,0))HueGreen = hsvRef.H'Obtain new huehsvRef = RasterHsvColor.FromRasterColor(New RasterColor(255, 128, 0))Change = hsvRef.H - HueGreenIf (Change>0) ThenHueChange = ChangeElseHueChange = (Change + Length - 1)End IfHueGreen *= (Length - 1)/255HueChange *= (Length - 1)/255'Set values in HueTable, MaskTableHueTable(HueGreen) = (HueTable(HueGreen) + HueChange)MaskTable(HueGreen) = 1'set the hues near green (+/- 15)Count = (15 * (Length - 1))/255i = INCREMENT_S1(HueGreen, Length)Do While Count > 0HueTable(i) = ADD_S1(CInt(HueTable(i)), HueChange, Length)MaskTable(i) = 1i = INCREMENT_S1(i, Length)Count -= 1LoopCount = (15 * (Length - 1))/255i = DECREMENT_S1(HueGreen, Length)Do While Count > 0HueTable(i) = ADD_S1(HueTable(i), HueChange, Length)MaskTable(i) = 1i = DECREMENT_S1(i, Length)Count -= 1LoopDim command As RemapHueCommand = New RemapHueCommand(MaskTable, HueTable, Nothing, Nothing, Length)command.Run(image)' Save result imageDim codecs As RasterCodecs = New RasterCodecs()codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24)image.Dispose()End Sub
Leadtools.ImageProcessing.Color Namespace
Changing Brightness and Contrast
HistogramContrastCommand Class
HistogramEqualizeCommand Class
|
Products |
Support |
Feedback: RemapHueCommand Class - Leadtools.ImageProcessing.Color |
Introduction |
Help Version 19.0.2017.3.21
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.