Note: You must be registered in order to post a reply. To register, click here. Registration is FREE!
T O P I C R E V I E W
PeterPanino
Posted - Apr 15 2021 : 14:41:12 Which is the best/fastest method to replace explicitly a specific color in the WHOLE image, using a custom TOLERANCE?
I have tried the \Demos\ImageAnalysis\Palette demo. It works, but it has no way to set a tolerance.
Would I have to scan all pixels in the image and check whether a pixel's color is in the range of tolerance and then change its color, or is there a BUILT-IN function for this purpose in ImageEn?
The concept of "Tolerance" in this context has to be better defined: Using the HSL color model, Tolerance could be defined as: • Hue tolerance • Saturation tolerance • Lightness tolerance
This means that a function that replaces a color should have these parameters:
procedure TformMain.ReplaceColor(aSourceColor, aTargetColor: TColor; AHueTolerance, ASatTolerance, ALumTolerance: Integer);
begin
for each Pixel in AllImagePixels do
begin
if ((Pixel.Hue - aSourceColor.Hue) < AHueTolerance) and ((Pixel.Sat - aSourceColor.Sat) < ASatTolerance) and ((Pixel.Lum - aSourceColor.Lum) < ALumTolerance) then
Pixel.Color := aTargetColor;
end;
end;
Is this pseudo-code logical?
What do you think?
6 L A T E S T R E P L I E S (Newest First)
xequte
Posted - Apr 20 2021 : 01:59:36 That works nicely. It is similar to chromakey (green screen) removal.
Posted - Apr 16 2021 : 06:49:06 The best results until now I had with this function:
procedure TForm1.btnTestClick(Sender: TObject);
const
T = 10; // tolerance value
var
H, S, V: Integer;
begin
ColorToHSV($0001FD, H, S, V); // this is a color in the image
imgTest.Proc.CastColorRange(
HSVToColor(H, S + T, V - T), // BeginColor
HSVToColor(H, S - T, V + T), // EndColor
clBlue); // CastColor
end;
PeterPanino
Posted - Apr 16 2021 : 06:20:36 A completely different approach would be TImageEnProc.CastColorRange, for example:
procedure TForm1.btnTestClick(Sender: TObject);
const
T = 10; // tolerance value
var
rgb: TRGB;
begin
rgb := TColor2TRGB( $00FEFE ); // this is a color in the image
imgTest.Proc.CastColorRange(
TRGB2TColor(CreateRGB(rgb.r + T, rgb.g + T, rgb.b + T)), // BeginColor
TRGB2TColor(CreateRGB(rgb.r - T, rgb.g - T, rgb.b - T)), // EndColor
clRed); // CastColor
end;