Jump to content

Color Checking (need urgent help please)


Recommended Posts

So I procrastinated for way too long to do my science fair project, and it's now due in 3 days. And it has to be on Earth Science. So what does AutoIt and Earth Science have in common? Not much else but my project. I want to make a program that when you press "C", or any specific key, it will check the pixel color of the cursor and the area around it to try and figure out what basic color this is. The program will be used to find the color of sand. I want to do this because the program will then go on to tell you what the mineral composition of the sand is based on the color of the sand. But the problem comes when pixelgetcolor does not gets too specific a color. It just takes one dot from the many colors of the sand. I tried making the program take a few pixel colors of the surrounding pixels as well and then extract the colors with _ColorGetBlue, getred, and getgreen and then average all the blues, greens, and reds, but that didn't really work. Ideally I could keep in decimal form color and just find a range of colors it could be to be each of the sands, but this would require a good explanation of decimal color. Please any help you could offer will be greatly appreciated, and the sooner the better. Thank you very much.

#include <misc.au3>
#Include <Color.au3>

global $colorHEXfin

while 1
    if _IsPressed("43") Then
        $mouse = MouseGetPos()
        $color1 = PixelGetColor($mouse[0], $mouse[1])
        ExitLoop
    EndIf
WEnd


$color2 = PixelGetColor($mouse[0] + 2, $mouse[1] + 2)

$colorSum = $color1 + $color2
$colorAvg = $colorSum/2

$colorHEX = Hex($colorAvg, 6)


$colorRed1 = _ColorGetRed($color1)
$colorBlue1 = _ColorGetBlue($color1)
$colorGreen1 = _ColorGetGreen($color1)

$colorRed2 = _ColorGetRed($color2)
$colorBlue2 = _ColorGetBlue($color2)
$colorGreen2 = _ColorGetGreen($color2)


$colorRedSum = $colorRed1 + $colorRed2
$colorRedAvg = $colorRedSum/2

$colorBlueSum = $colorBlue1 + $colorBlue2
$colorBlueAvg = $colorBlueSum/2

$colorGreenSum = $colorGreen1 + $colorGreen2
$colorGreenAvg = $colorGreenSum/2

dim $colorHEXfin[3] = [$colorRedAvg, $colorGreenAvg, $colorBlueAvg]

if not IsInt($colorHexfin[0]) Then
    $colorHexfin[0] = $colorHexfin[0] + 0.5
EndIf

if not IsInt($colorHexfin[1]) Then
    $colorHexfin[1] = $colorhexfin[1] + 0.5
EndIf

if not IsInt($colorHexfin[2]) Then
    $colorHexfin[2] = $colorHexfin[2] + 0.5
EndIf

MsgBox(0, $colorHEXfin[0] & " " & $colorHEXfin[1] & " " & $colorHEXfin[2], $colorHEXfin[0] & " " & $colorHEXfin[1] & " " & $colorHEXfin[2])

if $colorHEXfin[1] > 125 Then
    MsgBox(0,"The Sand is Composed of...", "Olivine") ;;;;; Green sand is composed of this, and i didn't finish the list of all the possible compositions
EndIf
Link to comment
Share on other sites

The big problem here is that the range of colors by pixel can be huge and you will need to do something like "hex color range 000000 - 0000ff = granite" and "hex color 0000ff - 00ff00 = obsidian" etc. My thought is that you could take 100 close range samples of the sand and average the answer. The larger number of samples is going to give you a closer representation of what the color would look like to the naked eye from a small distance but the individual pixels will be very far off from one another. Also wouldn't sand be made up of several different minerals? Is your program going to just choose one based on the color?

Random thought: For presentation you could average the hex color and then generate a web page with the background being the sand and add html to describe the mineral contents. Three days... I don't envy you. Good Luck.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Look in the helpfile for PixelSearch(). PixelSearch might be what you need becuase you can also look for a range of colors too.

Another thought, call me dumb, I'm thinking that a color is actually comprised of three seperate pixels -- one for each primary color. Isn't this right? So, if you wanted to find yellow you need to actually look at three seperate pixels for the correct combination. Or maybe the pixel functions do this already, I dunno.

Edited by jaberwocky6669
Link to comment
Share on other sites

Could you post a sample picture of what image do you have to recognize?

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Link to comment
Share on other sites

Thank you all for your help. Luckily I think I really only need to check for a couple of colors of sand because apparently there really aren't that many colors a beach can be. My research says it's only white, black, green, and pink. So these are all pretty different colors and I think I might have a good enough version to at least fake my way through a presentation.

And an example picture I just got off google is something like this:

http://t2.gstatic.com/images?q=tbn:ANd9GcSxN3WIGq4ol-hSvWHQ3Ta3kF2NXIkQ0wgP8GPNwceYHktwwmVBmw

My final-ish version would work for this pictures and the other ones I'll get for my presentation. Thanks again very much. Your comments have helped.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...