Jump to content

Assigning values to a large array


Recommended Posts

Hi,

I apologise if there's an obvious answer to this or if it has been answered elsewhere. I've hunted around for a few hours trying to solve this seemingly trivial problem but no joy muttley

I'm trying to populate an array holding 1s and 0s representing white and black pixels for a set of letters (for a simple OCR script). There are 66 letters and each is a 12x13 pixel picture, made up of black and white only. I originally wanted to declare an array as follows:

Dim $letters_db[66][13][12] = [ _
[[0,0,0,1,0,0,0,0,1,0,0,0],[0,0,0... _
[[0,0,0,0,0,1,1,0,0,0,0,0],[0,0,0... _
[[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0... _
[[0,0,0,0,0,0,1,1,1,0,0,0],[0,1,0... _
... ]]]

where each line is a letter, each bracketed set on a line is a pixel row and each element of that set is a pixel column. This makes for a VERY long declaration and as it turns out too long, since only 4096 characters may be used in such a declaration (stops reading after the 11th letter, returns a syntax error). I thought to get around this I could declare the array and then assign the values afterward in chunks, but I'm not sure how to assign values to an array without doing it in an element-by-element list. I wanted something like this:

$letters_db[first 11 letters][13][12] = [ _
[[0,0,0...
...

$letters_db[next 11 letters][13][12] = [ _
[[0,0,0...
...

Should I be using a function to populate the array, reading from a table somewhere?

Is there a better way to do this?

Thanks for taking the time to read this ^^

Mint

Link to comment
Share on other sites

I have ran into this same prob many times personally. I learned to use this system

$Letters = StringSplit("121315654,54646464441,654646464,65464867,654946163", ",")

$Xpos = StringSplit("322,157,458,655,214", ",")

$Ypos = StringSplit("122,357,266,129,452", ",")

For $x = 1 To 5
    
    MsgBox(0x0, $x, "Letter = " & $Letters[$x] & @CRLF & "X pos = " & $Xpos[$x] & @CRLF & "Y pos = " & $Ypos[$x], 3)
    
Next

8)

NEWHeader1.png

Link to comment
Share on other sites

Hi,

I apologise if there's an obvious answer to this or if it has been answered elsewhere. I've hunted around for a few hours trying to solve this seemingly trivial problem but no joy :)

I'm trying to populate an array holding 1s and 0s representing white and black pixels for a set of letters (for a simple OCR script). There are 66 letters and each is a 12x13 pixel picture, made up of black and white only. I originally wanted to declare an array as follows:

Dim $letters_db[66][13][12] = [ _
[[0,0,0,1,0,0,0,0,1,0,0,0],[0,0,0... _
[[0,0,0,0,0,1,1,0,0,0,0,0],[0,0,0... _
[[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0... _
[[0,0,0,0,0,0,1,1,1,0,0,0],[0,1,0... _
... ]]]

where each line is a letter, each bracketed set on a line is a pixel row and each element of that set is a pixel column. This makes for a VERY long declaration and as it turns out too long, since only 4096 characters may be used in such a declaration (stops reading after the 11th letter, returns a syntax error). I thought to get around this I could declare the array and then assign the values afterward in chunks, but I'm not sure how to assign values to an array without doing it in an element-by-element list. I wanted something like this:

$letters_db[first 11 letters][13][12] = [ _
[[0,0,0...
...

$letters_db[next 11 letters][13][12] = [ _
[[0,0,0...
...

Should I be using a function to populate the array, reading from a table somewhere?

Is there a better way to do this?

Thanks for taking the time to read this ^^

Mint

You could switch to binary. 12 * 13 = 156 bits = 19 bytes (plus four spare bits). Or, 24 bytes if you provide 16 x 12 so it will be easier to address rows of pixels. If you are comfortable with binary operations, your array would look like:
$avLeters[67] = [66, _
Binary("0x210FEDCBA9876543210"), _
Binary("0x10FEDCBA98765432102"), _

; ... etc

Binary("0x0FEDCBA987654321021"), _
Binary("0xFEDCBA9876543210210")]

muttley

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

That code seems to be for a 2-dimensional array, with letter ID, xpos and ypos. Is there a way to extend it to 3 dimensions? Each letter in my data has 13 row values and 12 column values, a typical letter such as this "g" might contain data as below. Formatting is for clarity only.

0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0

0 1 1 1 0 1 0 0 0 0 0 0

1 1 0 0 1 1 0 0 0 0 0 0

1 0 0 0 0 1 0 0 0 0 0 0

1 0 0 0 1 1 0 0 0 0 0 0

1 1 0 1 1 1 0 0 0 0 0 0

0 0 1 0 0 1 0 0 0 0 0 0

0 0 0 0 0 1 0 0 0 0 0 0

1 1 0 0 1 1 0 0 0 0 0 0

0 1 1 1 1 0 0 0 0 0 0 0

I need to write 66 letters similar to this to an array of the form $letters_db[66][13][12] or some equivalent for storage. This "database" array is used for pixel-by-pixel, letter-by-letter comparison with a test picture.

Edit: didn't see psalty's post, gonna read that first

Edited by Mint
Link to comment
Share on other sites

That code seems to be for a 2-dimensional array, with letter ID, xpos and ypos. Is there a way to extend it to 3 dimensions? Each letter in my data has 13 row values and 12 column values, a typical letter such as this "g" might contain data as below. Formatting is for clarity only.

0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0

0 1 1 1 0 1 0 0 0 0 0 0

1 1 0 0 1 1 0 0 0 0 0 0

1 0 0 0 0 1 0 0 0 0 0 0

1 0 0 0 1 1 0 0 0 0 0 0

1 1 0 1 1 1 0 0 0 0 0 0

0 0 1 0 0 1 0 0 0 0 0 0

0 0 0 0 0 1 0 0 0 0 0 0

1 1 0 0 1 1 0 0 0 0 0 0

0 1 1 1 1 0 0 0 0 0 0 0

I need to write 66 letters similar to this to an array of the form $letters_db[66][13][12] or some equivalent for storage. This "database" array is used for pixel-by-pixel, letter-by-letter comparison with a test picture.

Edit: didn't see psalty's post, gonna read that first

This is what the array looks like, done as I described with 16 bits (2 bytes) per row, with only 'g' in it:
#cs
; The lower case 'g'
0 0 0 0, 0 0 0 0, 0 0 0 0
0 0 0 0, 0 0 0 0, 0 0 0 0
0 0 0 0, 0 0 0 0, 0 0 0 0
0 0 0 0, 0 0 0 0, 0 0 0 0
0 1 1 1, 0 1 0 0, 0 0 0 0
1 1 0 0, 1 1 0 0, 0 0 0 0
1 0 0 0, 0 1 0 0, 0 0 0 0
1 0 0 0, 1 1 0 0, 0 0 0 0
1 1 0 1, 1 1 0 0, 0 0 0 0
0 0 1 0, 0 1 0 0, 0 0 0 0
0 0 0 0, 0 1 0 0, 0 0 0 0
1 1 0 0, 1 1 0 0, 0 0 0 0
0 1 1 1, 1 0 0 0, 0 0 0 0
#ce

Global $avLetters[2] = [1, Binary("0x0000000007400CC0084008C00DC0024000400CC00780")]
ConsoleWrite("$avLetters[1] = " & $avLetters[1] & @LF)
For $row = 1 To BinaryLen($avLetters[1]) / 2
    $binPixels = BinaryMid($avLetters[1], ($row * 2) - 1, 2)
    ConsoleWrite("Row " & $row & " = " & $binPixels & @LF)
Next

muttley

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...