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
 Most dominant colors? Most contrasting color?

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 - Sep 12 2017 : 13:51:25
Hello!

• How can I get the eight most dominant colors from an image?

• And how can I get the most contrasting color for each of these dominant colors? (By contrasting color I mean to get the best readability of a text color where the background is one of the dominant colors).

Are there any such routines already written by anybody?
4   L A T E S T    R E P L I E S    (Newest First)
w2m Posted - Sep 15 2017 : 12:26:52
I use the contrasting color functions to make sure any text on or in the image is readable. I do not have any other functions. Try http://www.stackoverflow.com

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
PeterPanino Posted - Sep 15 2017 : 06:34:04
Bill,

I made a test with your contrast-color functions:



The screenshot contains 6 rows, where the left-most field is a random input color and the smaller fields on the right side are the respective results of your functions.

You can see that ContrastingColor gets either White or Black, GetContrastingColor gets a somewhat contrasting color and GetContrastColor returns ALWAYS White.

So, are these functions based on a scientific color model?
PeterPanino Posted - Sep 12 2017 : 14:51:25
The first question could not have a sensible simple single-color answer, as what creates the human impression of the most dominant color in an image may be is rather a range or a bandwidth of colors.

And this range is always a function of the extent of the total uniformity of colors in the image, so it would be relative and not absolute.

So the most dominant color in an image would be the average of a color range which itself is a function of the color uniformity of the image.
w2m Posted - Sep 12 2017 : 14:42:12
Here are three different ways to get the contrasting color of a given color:
function ContrastingColor(const AColor: TColor): TColor;
{ Return contracting color of the passed color. }
begin
  if ((AColor and $FF) * 77 + ((AColor shr 8) and $FF) * 150 +
    ((AColor shr 16) and $FF) * 29) > 127 * 256 then
    Result := clBlack
  else
    Result := clWhite;
end;

function GetContrastingColor(AColor: TColor): TColor;
{ Get a contrasting color. }
begin
  AColor := ColorToRGB(AColor); { convert system-defined colors }
  Result := (AColor + $000080) and $0000FF + { red component }
    (AColor + $008000) and $00FF00 + { green component }
    (AColor + $800000) and $FF0000; { blue component }
end;

function GetContrastColor(AColor: TColor): TColor;
{ Get contrast color. }
begin
  AColor := ColorToRGB(AColor); { convert system-defined colors }
  if (AColor + AColor shr 8 + AColor shr 16) and $0000FF >= $180 then
    Result := clBlack
  else
    Result := clWhite;
end;

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development