Sign in to follow this  
Followers 0
DefinedV

Comparing Colors

7 posts in this topic

#1 ·  Posted (edited)

Hello, I was wondering if there was a simple way of comparing two hex values with regard to 2 shades of variation. Also is there a way to check if a color is darker than another?

i.e

if $color1hex == $color2hex , however instead of a direct match, it takes into account 2 shades of variation.

-Thank you

Edited by DefinedV

Share this post


Link to post
Share on other sites



Sorry, I apologize if I came across as unclear. But let me clarify; the PixelGetColor function returns a hex value, but I would like to account for color variation, 2 shades in this case. I would like to compare the value with a previous value I retrieved and if it's within 2 shades of each other, than return true, otherwise return false.

Thanks

Share this post


Link to post
Share on other sites

I'd guess you'd need to define a function for that one.

Can't help you here because I don't know how to quantify what "within 2 shades" means? The hex value return would be RGB values, I'd assume, but I have no idea what calculation you'd need to say that one color is within two shades of another.

Share this post


Link to post
Share on other sites

If it means anything, The helpfile says Pixelgetcolor returns a decimal value.

From experience I know you can compare it to a hex and get a correct result, but I too dont know enough about colours to work out which wold be darker.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

You probably need to do a little search about color matching to define your own appreciation of what you're ready to consider "close enough" for your needs.

Anyway and as just stated, colors you read are RGB values which, for elementary practice, can bee seen as a tridimensionnal space with coordinates bounded in [0..255], which is the so-called color-cube.

The simplest way to estimate how close are two points in N-space is to compute their (Euclidean) distance. In your case, N=3 and if your pixels' colors, once split in Red, Green and Blue components, are:

Local $pixel1[3] = [$r1, $g1, $b1]

Local $pixel2[3] = [$r2, $g2, $b2]

then the "simple" colorimetric distance separing them is:

Local $ColorDist = Sqrt(($r2 - $r1) ^ 2 + ($g2 - $g1) ^ 2 + ($b2 - $b1) ^ 2)

The smallest result you get, the closest the two colors are. The Sqrt() isn't even meaningful in your case so you can get along without it and without loosing any significance.

In RGB space, the higher values are the most intense: black is {0, 0, 0} white is {255, 255, 255}.

There are a large number of ways to appreciate and quantitize colors, but RGB is by far the simplest.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks everyone, really appreciate it. :(

Edited by DefinedV

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0