LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a portion of a binary 2D U8 array

My data is stored as an 2D U8 array as a 480X640 matrix.

What if I only want to read a portion of that matrix using the Read File VI? Can this be done with a 2D array binary file? e.g. I want a 100X120 matrix after the read file VI. Possible?
0 Kudos
Message 1 of 4
(2,358 Views)
The simplest solution is to read the entire file, then to use the array subset function to extract the portion you want. Of course this implies that you have enough memory for that. A 640x480 U8 array is only about 300 Kbytes. Even if you have several copies of it, everything should fit into any modern PC RAM.
Can you be a bit more explicit about your requirements?
CC
Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
0 Kudos
Message 2 of 4
(2,347 Views)
Thats the issue. I don't want the whole 480X640 array resident in memory. I'm running my app on a PDA target so memory is tight. I'm hoping there is a way. Maybe I should save the matrix as binary 1D arrays, one for column and the other for row. I might be able to extract a portion of both arrays using the Read File VI. I'm looking into this as I type.
0 Kudos
Message 3 of 4
(2,334 Views)
The read file vi offers the possibility of reading a specified number of bytes starting at a given offset. You could write a function to read one line at a time in a loop to extract the desired array chunk.
Assuming that your array is organized as 640 rows of 480 columns and you want to extract a chunk of 120 rows of 100 columns, starting at XY position 50, 100 you could:
1/ initialize a 120x100 array
2/ open the file
3/ calculate the file offset : line 100, column 50 : offset = 100x480 + 50
4/ read 100 bytes at offset position
5/ replace the first array line
6/ repeat 2, 120 times, replacing the corresponding array lines

Ask if you have problems while implementing that.
Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
0 Kudos
Message 4 of 4
(2,314 Views)