Sign in to follow this  
Followers 0
ExodduS

Count Number of squares

11 posts in this topic

i have a screen like the attach

i need to count the number of white squares in the big black square(for a game)

is that possibel?

can any1 help me with the function?

i was thinking something like that:

1) verify a pixel

2) if it's not black is the start of a square

3) verify next pixel if its black i got 1 square

4) if not, it's still the square

5) go to 1)

until the area has been search and i got the number of white squares

ok, thank you very much!

Share this post


Link to post
Share on other sites



i have a screen like the attach

i need to count the number of white squares in the big black square(for a game)

is that possibel?

can any1 help me with the function?

i was thinking something like that:

1) verify a pixel

2) if it's not black is the start of a square

3) verify next pixel if its black i got 1 square

4) if not, it's still the square

5) go to 1)

until the area has been search and i got the number of white squares

ok, thank you very much!

<{POST_SNAPBACK}>

just have a couple of for loops. check each pixel in the image. if the pixel above the one being examined is black, and the one to the left of it is, then it's the top left corner of the square, otherwise move on to next pixel. if you have 5 squares, you're gonna have 5 top left corners....

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

i got the idea, the only problem is this, how to make it?

for example, i use the PixelSearch for the first pixel or just make a loop and use PixelGetColor for every pixel of the image?

what is less time consuming, what is better

ty

Share this post


Link to post
Share on other sites

i got the idea, the only problem is this, how to make it?

for example, i use the PixelSearch for the first pixel or just make a loop and use PixelGetColor for every pixel of the image?

what is less time consuming, what is better

ty

<{POST_SNAPBACK}>

here's a little quick code... operating on a few assumptions though, 1) top left pixel of pic is 0,0 bottom right is 99,99. 2) PixelGetColor() for a black pixel will return 0 and i think that's that...

$squarecounter = 0
$left = 0
$up = 0
for $x = 0 to 99
    for $y = 0 to 99
        if $x > 0 then 
            $left = 1
        EndIf
        if $y > 0 then
                $up = 1
        EndIf
            
        if $up and $left Then
                if PixelGetColor($x,$y -1) = 0 and PixelGetColor($x -1,$y) = 0 then 
                    $squarecounter = $squarecounter + 1
                EndIf
            elseif $up Then
                if PixelGetColor($x,$y-1) = 0 then 
                    $squarecounter = $squarecounter + 1
                EndIf
            elseif $left Then
                if PixelGetColor($x-1,$y)= 0 then 
                    $squarecounter = $squarecounter +1
                EndIf
        EndIf
    Next
Next
    msgbox(0,"Squares","There are " & $squarecounter & " squares")

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

where there's a if $x > 0 is a pixelgetcolor right?

and shouldnt be a else for making $up and $left = 0?

ty

Share this post


Link to post
Share on other sites

where there's a if  $x > 0 is a pixelgetcolor right?

and shouldnt be a else for making $up and $left = 0?

ty

<{POST_SNAPBACK}>

$up and $left are to determine if there is a square above and to the left... because it's possible that a pixel with an x or y coord of 0 will be a white square, or the corner square we're looking for... so if $up and $left are both 1's, then that means there are squares above and to the left, so both have to be checked, otherwise, only squares that exist are checked... make sense?

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

yeah sure

but then u could make

for $x = 1 :)

and also there's no further checking to see

if PixelGetColor($x,$y -1) = 0 and PixelGetColor($x -1,$y) = 0 AND PixelGetColor($x, $y) = WHITE then

anyway, i got the idea ty

Share this post


Link to post
Share on other sites

yeah sure

but then u could make

for $x = 1 :)

and also there's no further checking to see

if PixelGetColor($x,$y -1) = 0 and PixelGetColor($x -1,$y) = 0 AND PixelGetColor($x, $y) = WHITE then

anyway, i got the idea ty

<{POST_SNAPBACK}>

np, glad i could help

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

$squarecounter = 0
$left = 0
$up = 0
for $x = 21 to 985
    for $y = 432 to 715
        if $x > 21 then
            $left = 1
        EndIf
        if $y > 432 then
           $up = 1
        EndIf
            
        if $up and $left Then
                if PixelGetColor($x,$y -1) = Dec(0x282828) and PixelGetColor($x -1,$y) = Dec(0x282828) and PixelGetColor($x,$y) = Dec(0xFFFFFF) then
                    $squarecounter = $squarecounter + 1
                EndIf
            elseif $up Then
                if PixelGetColor($x,$y -1) = Dec(0x282828) and PixelGetColor($x,$y) = Dec(0xFFFFFF) then
                    $squarecounter = $squarecounter + 1
                EndIf
            elseif $left Then
                if PixelGetColor($x -1,$y) = Dec(0x282828) and PixelGetColor($x,$y) = Dec(0xFFFFFF) then
                    $squarecounter = $squarecounter +1
                EndIf
        EndIf
    Next
Next
    $stop1 = TimerDiff($start1)
    MsgBox(0,"Time",$stop1)
    MsgBox(0,"Squares","There are " & $squarecounter & " squares")

got like 90000 mill to run it, and it's too much time

is there anyway to make the check almost instant? i dont know, maybe other solution

Edited by ExodduS

Share this post


Link to post
Share on other sites

$squarecounter = 0
$left = 0
$up = 0
for $x = 21 to 985
    for $y = 432 to 715
        if $x > 21 then
            $left = 1
        EndIf
        if $y > 432 then
           $up = 1
        EndIf
            
        if $up and $left Then
                if PixelGetColor($x,$y -1) = Dec(0x282828) and PixelGetColor($x -1,$y) = Dec(0x282828) and PixelGetColor($x,$y) = Dec(0xFFFFFF) then
                    $squarecounter = $squarecounter + 1
                EndIf
            elseif $up Then
                if PixelGetColor($x,$y -1) = Dec(0x282828) and PixelGetColor($x,$y) = Dec(0xFFFFFF) then
                    $squarecounter = $squarecounter + 1
                EndIf
            elseif $left Then
                if PixelGetColor($x -1,$y) = Dec(0x282828) and PixelGetColor($x,$y) = Dec(0xFFFFFF) then
                    $squarecounter = $squarecounter +1
                EndIf
        EndIf
    Next
Next
    $stop1 = TimerDiff($start1)
    MsgBox(0,"Time",$stop1)
    MsgBox(0,"Squares","There are " & $squarecounter & " squares")

got like 90000 mill to run it, and it's too much time

is there anyway to make the check almost instant? i dont know, maybe other solution

<{POST_SNAPBACK}>

could you attach the pic you're using to test? i want to see if i can't speed it up, but want to use the same size, etc...

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

i have a couple of ideas to cut down on the number of comparisons, i will test them and post code and results...

Here's what i got.... don't think INSTANT is really possible, but can really cut the time by reducing the number of comparisons. instead of checking each pixel, i ran with the the pixelchecksum to check 4 pixels at a time, and evaluate if white pixels were found. using the same image image that was taking 8000+ each time now i'm averaging about 2600.... if you wanted to go through and figure the possible checksums for 3x3 blocks instead of 2x2 blocks, i'm sure you could shave some more time off. here's the code: <you're going to have to change the ranges on the For loops, and filenames etc...>

winactivate("C:\Documents and Settings\lv_sdesanti\Desktop\pixel.jpg - Microsoft Internet Explorer")
$squarecounter = 0
$left = 0
$up = 0
$START = TimerInit()
for $x = 12 to 147 STEP 2
    for $y = 114 to 311 STEP 2
        select 
            case PixelChecksum($x,$y,$x+1,$y+1)=1304300533 ;ALL 4 ARE WHITE
                if $x = 12 and $y = 114 Then
                    $squarecounter = $squarecounter  + 1
                Else
                    IF $Y = 114 AND PixelGetColor($X-1,$Y)=0 Then
                    $squarecounter = $squarecounter  + 1
                    MouseMove($X,$Y,0)
                    MSGBOX(0,"HERE","HERE")
                    EndIf
                
                    IF PixelChecksum($X-1,$Y-1,$X,$Y) = 101057278 Then
                    $squarecounter = $squarecounter  + 1
                    EndIf
                EndIf
            case PixelChecksum($x,$y,$x+1,$y+1)=351733243;VERTICAL WHITE PAIR
                
                if $x = 12 Then
                    $squarecounter = $squarecounter  + 1
                Else
                    IF PixelGetColor($X+1,$Y -1) = 0 Then
                    $squarecounter = $squarecounter  + 1
                    EndIf
                EndIf
                
            CASE PixelChecksum($x,$y,$x+1,$y+1)=101057278;HORIZONTAL WHITE PAIR
                $squarecounter = $squarecounter  + 1
        EndSelect

    Next

Next
$STOP = TimerDiff($START)
MSGBOX(0,"TIME",$STOP)
msgbox(0,"squarecounter",$squarecounter)

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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
Sign in to follow this  
Followers 0