ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Replace color in whole image?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

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.

Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Apr 17 2021 : 13:18:41
I made some interesting color experiments with this demo, for example:

PeterPanino Posted - Apr 17 2021 : 09:29:15
I invite you all to run my ReplaceColorTest demo project and tell me any bugs and suggestions:



attach/PeterPanino/202141792839_ReplaceColorTest.zip
95.34 KB
xequte Posted - Apr 16 2021 : 18:24:05
Hi Peter

That should work well enough. You could also write a routine to iterate the scanlines. That is quite straightforward:

https://www.imageen.com/help/TIEBitmap.ScanLine.html

Nigel
Xequte Software
www.imageen.com
PeterPanino 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;


Would that be a viable option?