public RemapHueCommand() Public Function New() - (instancetype)init public RemapHueCommand() public:RemapHueCommand();
Run the RemapHueCommand on an image and change all green hues (and hues near green).
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing.Color;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 imageRasterCodecs codecs = new RasterCodecs();codecs.ThrowExceptionsOnInvalidImages = true;RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg"));// Prepare the commandint 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 tablesint[] MaskTable = new int[Length];int[] HueTable = new int[Length];//Initialize tablesfor (int i = 0; i < Length; i++){MaskTable[i] = 0;HueTable[i] = i;}//Get the hue for greenRasterHsvColor hsvRef = RasterHsvColor.FromRasterColor(new RasterColor(0, 255, 0));int HueGreen = hsvRef.H;//Obtain new huehsvRef = 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, MaskTableHueTable[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:\LEADTOOLS21\Resources\Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessing.ColorPublic Function INCREMENT_S2(ByVal x As Integer, ByVal Length As Integer) As IntegerReturn ((x + 1) Mod Length)End FunctionPublic Function DECREMENT_S2(ByVal x As Integer, ByVal Length As Integer) As IntegerReturn ((x + (Length - 1)) Mod Length)End FunctionPublic Function ADD_S2(ByVal x As Integer, ByVal y As Integer, ByVal Length As Integer) As IntegerReturn ((x + y) Mod Length)End FunctionPublic Sub RemapHueCommandConstructorExample()Dim codecs As New RasterCodecs()codecs.ThrowExceptionsOnInvalidImages = TrueDim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg"))' Prepare the commandDim 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 IfDim MaskTable() As IntegerDim HueTable() As Integer'Allocate tablesReDim MaskTable(Length - 1)ReDim HueTable(Length - 1)Dim i As Integer'Initialize tablesFor i = 0 To Length - 1MaskTable(i) = 0HueTable(i) = iNext'Get the hue for greenDim hsvRef As RasterHsvColor = RasterHsvColor.FromRasterColor(New RasterColor(0, 255, 0))Dim HueGreen As IntegerHueGreen = hsvRef.H'Obtain new huehsvRef = RasterHsvColor.FromRasterColor(New RasterColor(255, 128, 0))Dim Change As Integer = hsvRef.H - HueGreenDim HueChange As IntegerIf (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_S2(HueGreen, Length)Dim Count As IntegerFor Count = (15 * (Length - 1)) \ 255 To 1 Step -1i = INCREMENT_S2(i, Length)HueTable(i) = ADD_S2(HueTable(i), HueChange, Length)MaskTable(i) = 1Nexti = DECREMENT_S2(HueGreen, Length)For Count = (15 * (Length - 1)) \ 255 To 1 Step -1i = DECREMENT_S2(i, Length)HueTable(i) = ADD_S2(HueTable(i), HueChange, Length)MaskTable(i) = 1NextDim command As RemapHueCommand = New RemapHueCommandcommand.Mask = MaskTablecommand.HueTable = HueTablecommand.SaturationTable = Nothingcommand.ValueTable = Nothingcommand.LookUpTableLength = Lengthcommand.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:\LEADTOOLS21\Resources\Images"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
