getpixelcolor of all pixels in a 15x14 box

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

getpixelcolor of all pixels in a 15x14 box

Post by Snickers » Thu Dec 15, 2005 10:07 pm

What is the best way to getpixelcolor> or all pixels inside of an area that is 15x14 pixels.

the only way i can think of would require me to make 210 variables and 210 copy and pasted sections of code and then changing the name of each variable and pixel in each one.

I would also like to save the pixel colors to a notepad file or some file that I can copy and paste into excel and then sort the pixel colors and then count them manually to see which colors show up most frequently.

Is there a way to do this easier than so much copy and paste?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Dec 15, 2005 10:25 pm

Use two nested loops, one for the x coords and one for the y coords and put the results in an array. You then output contents of array to text file.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Dec 15, 2005 10:28 pm

Similar question and answer here:
http://www.mjtnet.com/forum/viewtopic.php?t=401
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Thu Dec 15, 2005 11:35 pm

i dont know how to use an array or what it is really. the help file shows these examples:

Let>Names[1]=Fred
Let>Names[2]=Sally
Let>Names[3]=Geoff

Let>k=2
Message>Names[%k%]
Let>Names[%k%]=Louise

does this mean that I would have to type in 210 different variables manually.

this example in the help file really didnt tell me anything about arrays whatsoever.

I know how to get pixel from each location

//Get pixel colorS
//x and y coords are where the search will begin

Let>x=0
Let>y=0
Let>xcount=15
Let>ycount=14

Label>Loop
GetPixelColor>x,y,HOW DO I SIGN THIS VALUE TO A BUNCH OF DIFFERENT VARIABLES
If>%x%NextColumn
Let>x=%x%+1
Goto>Loop

Label>NextRow
If>%y%=%ycount%,END
Let>y=%y%+1
Let>x=0
Goto>Loop

Label>END

how do i save the file to text?
how do i make arrays?

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Fri Dec 16, 2005 1:21 am

I got it!

wait>5
//Get pixel color and save to text file
//x and y coords are where the search will begin

Let>x=635
Let>y=528
Let>xcount=%x%+14
Let>ycount=%y%+13
Let>count=0
Let>VAREXPLICIT=0

Let>k=0
Label>Loop
Let>k=%k%+1
GetPixelColor>x,y,color
add>count,1
Let>var_%k%=%color%
WriteLn>c:\varexplicit_test.txt,wresult,var_%k%

If>%x%NextColumn
add>x,1
goto>Loop

Label>NextRow
If>%y%>%ycount%
goto>PRINT
ELSE
add>y,1
Let>x=635
endif

If>count=210
goto>PRINT
EndIF
goto>Loop

Label>PRINT
Run>Notepad.exe c:\varexplicit_test.txt

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Dec 16, 2005 8:53 am

Hi,

I was thinking of something like this:


Let>Colors[0,0]=

Let>XStart=10
Let>XStop=30
Let>YStart=10
Let>YStop=30

Let>x=XStart
Repeat>x
Let>y=YStart
Repeat>y
GetPixelColor>x,y,color
Let>Colors[%x%,%y%]=color
Let>y=y+1
Until>y>YStop
Let>x=x+1
Until>x>XStop


Note the multi-dimensional array. Once the operation is complete, say you want to get the color at position 16,28 you would just do:

Let>color=Colors[16,28]

Note also the use of nested Repeat/Until loops which simplify the code considerably.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts