Jump to content

Pixel Check Sum: can I use it for math calculations?

Recommended Posts

I could use a bit of math help.

What I'd like to do is sample a 5x5 pixel area with PixelChecksum. I would then sample again a few seconds later to check for a change as seems to be the normal usage.

Can I do any useful maths on the PixelChecksum results? For instance, if I subtracted the two sample values would it tell me anything about pixel color content? Might I know that a color shift has happened to maybe Blue or Red for instance? Or would I have to do that on a per pixel sample? And if that is the case... what math would i use to compare an RGB value against another to detect a shift in color from neutral towards Red or Blue?

From the docs:


A checksum only allows you to see if "something" has changed in a region - it does not tell you exactly what has changed.

Func _testShift()
    ; with PixelChecksum
    Local $toler=5
    Local $PCS1 = PixelChecksum($x + $toler, $y + $toler, $x - $toler, $y - $toler, 1, $windowHandle , 0)
    Local $PCS2 = PixelChecksum($x + $toler, $y + $toler, $x - $toler, $y - $toler, 1, $windowHandle , 0)
    If $PCS1 <> $PCS2 Then
        ; How to compare these meaningfully for colorshift?
    ; or with single pixel....
    Local $px1 =    PixelGetColor($x, $y, $windowHandle)
    Local $pxRGB1 = _ColorGetRGB($px1)
    Local $px2 =    PixelGetColor($x, $y, $windowHandle)
    Local $pxRGB2 = _ColorGetRGB($px2)
    If $px1 <> $px2 Then
        If $pxRGB1[0] < $pxRGB2[0] Then Red?
        If $pxRGB1[2] < $pxRGB2[2] Then Blue?


Link to comment
Share on other sites

In order to do that, I believe you would need to reverse the algorithm used (adler) to create the checksum, unfortunately I do not believe it can be reversed because it is essentially a hash (one way encryption).

I am not 100% on that, but fairly confident of it.

Edited by JohnOne

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

Monkey's are, like, natures humans.

Link to comment
Share on other sites

The only thing i can think of is something like this, it can get improved a lot, but this should give you the idea:

#include <Array.au3>

Func RegionGetPixelSum(Const $point_x, Const $point_y, Const $nSize, Const $nPrecision = 1)
    Local $aRet[1] = [0]
    Local $n = 1

    For $x = 0 To $nSize-1 Step $nPrecision
        For $y = 0 To $nSize-1 Step $nPrecision
            ReDim $aRet[$n + 1]
            $aRet[$n] = PixelGetColor($point_x + $x, $point_y + $y)
            $n += 1

    $aRet[0] = $n - 1
    Return $aRet
EndFunc   ;==>CheckPixel

Local const $start_x = 555
Local const $start_y = 555
Local Const $Size = 5; will be 5x5
Local Const $Spacing = 2; How much spacing between each pixel check

; Move our mouse so we know where to start search
MouseMove($start_x, $start_y)

; What region we want to keep an eye on
Local Const $sample = RegionGetPixelSum($start_x, $start_y, $Size, $Spacing)

; Store result here
Local $aResult[1][2]
Local $n = 0
; If we found something
Local $foundsomething = False

while 1
    ; Constantly check for changes
    Local $test = RegionGetPixelSum($start_x, $start_y, $Size, $Spacing)

    for $i = 1 to $sample[0]
        for $y = 1 to $test[0]
            ; Store all id of changes
            if $sample[$i] <> $test[$y] Then
                $foundsomething = True
                ReDim $aResult[$n + 1][2]
                $aResult[$n][0] = $sample[$i]
                $aResult[$n][1] = $test[$y]

    if $foundsomething Then

_ArrayDisplay($aResult,"Sample colours | Test colours")


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

  • Create New...