Hello,
Suppose you have two adjacent images (A & B) on your screen and suppose you want to do a series pixel color comparisons (ie comparing colors of certain pixels on the left with the colors of the corresponding pixels on the right).
I know some of the variables and functions to be used, but I'm not sure how to build them into a script.
For example:
The x-coordinates for the two comparison pixels could be represented by:
xA :=
xB :=
xDiff := xB - xA
Similarly, the y-coordinates would be:
yA :=
yB :=
yDiff := yB - yA
(although yDiff will usually be zero since the images will usually be adjacent to each other).
The incremental distance between each pixel to test is given as:
xInc := 0
yInc := 10
Note: The above increment values are for testing every 10th pixel in a column of pixels. The next column (10 pixels to the right) could then be tested in a similar manner.
And I know that the built-in variable A_Index would be needed to change the sampling location with each subsequent loop.
Here are the functions I came up with to actually check two corresponding pixels:
PixelGetColor, AColor, %xA%, %yA%, RGB
PixelGetColor, BColor, %xB%, %yB%, RGB
If (AColor = BColor)
The idea would be, using a looped script, to test a pair of pixels, then, if their colors are identical, move down 10 pixels to check the next pair. This process would continue until a non-matching pixel pair is discovered at which point the looping stops and a MsgBox displays the coordinates of the unmatched pixel(s).
I hope that's a non-confusing description of what I'm after and I hope I'm not biting off more than I can chew but I appreciate any assistance available.
Thanks
Compare pixel colors for a series of points in two adjacent images
-
- Posts: 312
- Joined: 19 Nov 2013, 08:44
Compare pixel colors for a series of points in two adjacent images
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
Re: Compare pixel colors for a series of points in two adjacent images
Code: Select all
xa1 := 51, xa2 := 100, ya1 := 51, ya2 := 100
xb1 := 101, xb2 := 150, yb1 := 51, yb2 := 100
x := xa1, y := ya1, incr := 10
Loop {
Loop {
PixelGetColor, c1, x, y
PixelGetColor, c2, x + xb1 - xa1, y
If (c2 != c1) {
MsgBox, 48, Mismatch, A color mismatch was found.`n`n(%x%`,%y%)
ExitApp
} Else y += incr
} Until (y > ya2)
x += incr, y := ya1
} Until (x > xa2)
MsgBox, 64, Matched, All pairs matched.
-
- Posts: 312
- Joined: 19 Nov 2013, 08:44
Re: Compare pixel colors for a series of points in two adjacent images
Wow. This is great. Thank you very much.
Not only does your script give me a solution but it gives me a better understanding of several functions which I've seen before but never quite known exactly how to use.
One question I have is if there is a way to put some +/- values in for the definition of a color match. For example, I just manually compared two pixels (which I know should match) and got the following:
PixelA: 180FC4
PixelB: 1611C6
So even though they are not identical, they are close enough that I would want them included as a match.
Another sort of off-topic question is if there's a command (to replace ExitApp) which will end the thread (ie the looping) but not kill the script (.ahk file). I want to attach a hotkey so that I can launch it from within a script that contains several other hotkey-triggered threads.
Thanks again
Not only does your script give me a solution but it gives me a better understanding of several functions which I've seen before but never quite known exactly how to use.
One question I have is if there is a way to put some +/- values in for the definition of a color match. For example, I just manually compared two pixels (which I know should match) and got the following:
PixelA: 180FC4
PixelB: 1611C6
So even though they are not identical, they are close enough that I would want them included as a match.
Another sort of off-topic question is if there's a command (to replace ExitApp) which will end the thread (ie the looping) but not kill the script (.ahk file). I want to attach a hotkey so that I can launch it from within a script that contains several other hotkey-triggered threads.
Thanks again
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
Re: Compare pixel colors for a series of points in two adjacent images
Maybe something like this.
Code: Select all
xa1 := 51, xa2 := 100, ya1 := 51, ya2 := 100
xb1 := 101, xb2 := 150, yb1 := 51, yb2 := 100
incr := 10
F3::
x := xa1, y := ya1
Loop {
Loop {
PixelGetColor, c1, x, y
x1 := x + xb1 - xa1
PixelSearch,,, x1, y, x1, y, c1, 5 ; Last parameter is the variation allowed
If ErrorLevel {
MsgBox, 48, Mismatch, A color mismatch was found.`n`n(%x%`,%y%)
Return
} Else y += incr
} Until (y > ya2)
x += incr, y := ya1
} Until (x > xa2)
MsgBox, 64, Matched, All pairs matched.
Return
-
- Posts: 312
- Joined: 19 Nov 2013, 08:44
Re: Compare pixel colors for a series of points in two adjacent images
Thanks Mike. I appreciate the modifications. I'm still working my way through this trying to understand it and I think I will definitely have some follow-up questions but not at present.
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.