Jump to content

# PixelSearch: Find redish/greenish/yellowish colors

## 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

#### Share this post

##### Share on other sites

Function PixelSearch

Look at the shade-variation parameter.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

#### Share this post

##### Share on other sites

Function PixelSearch

Look at the shade-variation parameter.

Let this be a lesson not to code until 4 a.m.

Thank you very much!

/Jason

#### Share this post

##### Share on other sites

You bet.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

#### Share this post

##### 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 & . 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

#### Share this post

##### 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```

## 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

×

• Wiki

• Back

• Git