Jump to content

PixelSearch: Find redish/greenish/yellowish colors


Aimjiel
 Share

Recommended Posts

Hi All,

I am looking for a way to tell if a pixel is a an unspecific tint/shade of a color. For instance, I want to know if it's red-ish, instead of feeding in just a straightforward color.

I don't fully understand how Autoit sees color, or how color works altogether, if someone could point me in the right direction, that'd be awesome!

Cheers,

Jason

Link to comment
Share on other sites

I'm not sure if PixelSearch is the answer to your problem. You need to read up on how RGB works. I'm no expert but had to look into it for a small project recently.

Basically "red-ish" as you describe is the hue. Hue is the relative difference of that channel (R ) over the other channels (G & B). So even if you find the red values that you are looking for (with PixelSearch) there is no guarantee it will appear red without knowing what the other two channels are - it could appear grey (all channels equal) or even green or blue (if those channels are greater relative to red). See Wiki.

PixelGetColor or _GDIPlus_BitmapLockBits are your friends. Then you might want to look into _ColorConvertRGBtoHSL to calculate hue. I believe this will give hue as an angle (in revolutions? (360° = 1 rev) the help file is unusally not so helpful here). For red you'd accept values of 0° ± say 15°.

QED

Link to comment
Share on other sites

i suggest PixelGetColor, from there you can BitAnd to get the red, green and blue values and run your own testing:

this isn't anything great, but it will return the most visible colour (default scite4autoit3 from last year's background colour returns #0000F9 from this) or the actual colour found if it doesn't think there's something noticeable

Func getHue($x, $y)
    Local $color = PixelGetColor($x, $y)
    Local $red = BitShift(BitAnd($color, 0xff0000), 16), $green = BitShift(BitAnd($color, 0xff00), 8), $blue = BitAnd($color, 255)
    Local $red2 = $red, $green2 = $green, $blue2 = $blue
    If $red > 30 Then 
        $red2 = $red - 5
    EndIf
    If $green > 30 Then 
        $green2 = $green - 5
    EndIf
    If $blue > 30 Then
        $blue2 = $blue - 5
    EndIf
    If ($red > $green) And ($red > $blue) Then
        If ($red2 >= $green) And ($red2 >= $blue) Then
            Return BitShift($red, -16)
        EndIf
    EndIf
    If ($green > $red) And ($green > $blue) Then
        If ($green2 >= $red) And ($green2 >= $blue) Then
            Return BitShift($green, -8)
        EndIf
    EndIf
    If ($blue > $green) And ($red < $blue) Then
        If ($blue2 >= $green) And ($red <= $blue2) Then
            Return $blue
        EndIf
    EndIf
    Return $color
EndFunc
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...