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
 Color approximation algorithm

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
Rocky Posted - Oct 14 2012 : 09:51:43
Say that I have a constant array of 16 colors, called Palette:

const
Palette :array[0..15] of TColor = ($F0F0F0, $101010, ... , $202020);

The contents are arbitrary and constant.


I would like to implement a function like this:

function MatchColor(Color :TColor) :integer;

MatchColor accepts *any* Color as a parameter and returns an index into the Palette array that points to the closest color to the one passed into the function. (Note: the Palette array is a global constant and visible to MatchColor)

So, in theory, it could be used like this:

NewColor := Palette[MatchColor(OldColor)];


How would such a function be implemented with ImageEn?
3   L A T E S T    R E P L I E S    (Newest First)
fab Posted - Oct 19 2012 : 00:15:52
Look at this:


var
  palette: array [0..2] of TRGB = ((b: 0; g: 0; r: 0), (b: 12; g: 20; r: 30), (b: 40; g: 60; r: 70));

procedure TForm1.Button22Click(Sender: TObject);
var
  RGBToFind: TRGB;
  idx: integer;
begin
  RGBtoFind := CreateRGB(28, 18, 10); // should match index 1 (b:12, g:20, r:30)
  idx := _GetSimilColor(palette, length(palette), RGBtoFind);
  ShowMessage(IntToStr(idx));
end;
Rocky Posted - Oct 18 2012 : 15:18:57
Thanks man. Sorry but as I am relatively novice in imageen could you please give me an example of GetSimilColor?
fab Posted - Oct 17 2012 : 11:00:43
ImageEn has the undocumented function _GetSimilColor (in imageenproc unit), which takes an array of TRGB (instead of TColor) values and, making a simple comparison, returns the index of the closest color.
Anyway you may require to compare colors in a different way (for example comparing color tonality, saturation, luminosity or a combination of them): for this task RGB2HSV could be useful.