Jump to content

how do i Find a unique colour


Con
 Share

Recommended Posts

I tried this but it took about 45 seconds just to check the first row of pixels at 1280 x 1024...

$test = _FindUniquePixel()
MsgBox(0,"",$test)

Func _FindUniquePixel()
    For $Y = 0 to @DesktopHeight
        For $X = 0 to @DesktopWidth
            ConsoleWrite($X & "," & $Y & @CRLF)
            $result = PixelGetColor ($X ,$Y )
            If NOT _FindMatchingPixel($X,$Y,$result) Then
                Return $result
            EndIf
        Next
    Next
    Return 0x000000
EndFunc

Func _FindMatchingPixel($XX,$YY,$color)
    For $Y = 0 to @DesktopHeight
        For $X = 0 to @DesktopWidth
            $result = PixelGetColor ($X ,$Y)
            If $result = $color AND NOT ($Y = $YY AND $X = $XX) Then
                Return true
            EndIf
        Next
    Next
    Return false
EndFunc
Link to comment
Share on other sites

Here is another method. This will return the decimal value of a unique pixel if it exists, or zero if there are no unique pixels.

It is rare for only one instance of a color to appear on the screen, the only way I could get this to work was to open photoshop and use the pencil tool to draw one pixel of an extreme color, then reduce the search area to only my photoshop stage.

;Max number of colors = 16777215

;Left,Top,Width,Height
$test = _FindUniquePixel2(452,438,100,100)
MsgBox(0,"",$test)

Func _FindUniquePixel2($LL, $TT, $WW, $HH)
    ;Max number of colors @ 1920x1200 = 2,304,000
    ;Max number of colors @ 1680x1050 = 1,764,000
    ;Max number of colors @ 1280x1024 = 1,310,720
    ;Max number of colors @ 1024x768 = 786,432
    ;Max number of colors @ 800x600 = 480,000
    
    ;Possible colors @ 32-bit = 16,777,215
    $Max = 16777215
    
    Local $colorOccurences[$Max + 1]
    For $Y = $TT to $TT + $HH
        For $X = $LL to $LL + $WW
            $result = PixelGetColor ($X ,$Y)
            
            ;Increment count of given color
            $colorOccurences[$result] += 1
        Next
    Next
    
    ;Search array for pixel with only one occurence and return the color value
    For $X = 0 to $Max
        If $colorOccurences[$X] = 1 Then Return $X
    Next
    
    Return 0
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...