04-17-2014 10:08 AM
Hi all.
I have a peice of code that
1)
- Reads an 8-bit grayscale image. Labview reports its depth as 8.
- Extracts the 1d array
- Repackages as a 2d array
- Draws using unflatten pixmap
(And this works fine.)
2)
- Initializes two arrays of 8-bit data, one array to one value, the other to another, the same size as the image.
- Repackages as a 2d array
- Draws using unflatten pixmap
However this doesn't work, the array is always initilized to 0; or at least, the images appear black (0).
What can be wrong?
(The above is for testing another piece of code).
04-17-2014 10:10 AM
Sorry hit the wrong button before adding the attachments.
04-17-2014 10:37 AM
After some more debugging -
strangely, if I initialize instead 2D array (and therefore get rid of the 1D-2D block), it all works fine.
Gunter
04-17-2014 10:49 AM
Sorry the .vi attached for the working case was wrong.
re-attached
Gunter
04-17-2014 04:58 PM
It's funny to watch people carry on conversations in these threads with themselves. I can laugh because i have done it.
04-17-2014 07:02 PM - edited 04-17-2014 07:04 PM
Hello Gunter,
The issue is not the reshape operation, but the multiply you do before generating the 1D array- your image of dimensions 200x201 requires ~40000 elements, which overflows the range of the I16 used to represent the bounds of the image. You then attempt to initialize arrays of <0 elements, which actually gives you an empty array. This is then reshaped to 200x201 and the empty elements are filled with the default value of zero.
Be careful when doing operations like this on minimally-represented numbers! It's relatively easy to overflow the bounds of 8- and 16-bit integers doing standard operations on reasonable-seeming values if you're not cautious. Those coercion dots (red) on your diagram are a hint, and try debugging using execution highlighting, etc. - as soon as you see that ~-32000 zip across the screen, you'd know what was happening.
Best Regards,