LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to save an array of 2D images into a BMP file

Hi,

 

i am generating a series of simulated dot-by-dot prints and displaying them in an array of 2D pictures (see print1.png). I have tried to merge all the elements of the array into a single image and to save it as a BMP file in order to be able to compare the differences between consecutive prints. Howeve, I am having some trouble converting between the different image formats.

 

- The "Unflatten Pixmap VI" only provides an output as 24-bit pixmap (even though a 4-bit or 1-bit output would suit my needs). 

- The "Flatten Pixmap VI" where I feed the full array of pixmaps produces an image with distorted colours (see print2.png)

- The "Write BMP File VI" creates a huge BMP file of about 86MB with the distorted image

- The "Draw Unflattened Pixmap VI" which I use for test purposes to display the merged picture in Labview also generates a distorted image; however, instead it inverts the colours (white dots over black background) and adds some blue traces on the scale.

 

Any suggestions about how I could make this work properly? 

 

Cheers

 

Download All
0 Kudos
Message 1 of 8
(4,429 Views)

Maybe - I'm not sure - but you try to play with inputs "Colors" and "Mask" for functions Flatten Pixmap VI, Unflatten Pixmap VI, in order to remove distortion of colors...
Regarding Unflatten Pixmap VI: in the help file it is written, that "... If you wire 32-bit image data to this VI, the VI returns a 24-bit pixmap. " - that's why you have a 4-bit or 1-bit output empty...

0 Kudos
Message 2 of 8
(4,355 Views)

Hi hun,

 

The "Write BMP File VI" creates a huge BMP file of about 86MB with the distorted image

What's the (pixel) size of your image? What's the color depth?

And last but not least: Why do you use BMP at all? Why not PNG?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 8
(4,348 Views)

I would agree with the recommendation to use PNG, but even if you do stick with BMP (which will be large anyway, because it has no compression), you just need to save it as a 1 bit image. Either do this at the source where you create the images, or you can do this in your print3 code, by having the array be a boolean array and converting the data to booleans (you will have to look at the values to determine the logic) and wiring that into the 1 bit input of the flatten VI.


___________________
Try to take over the world!
0 Kudos
Message 4 of 8
(4,332 Views)

kosist90,

 

How can I set a picture to 4-bit or 1-bit? All I do is create a blank 2D picture and draw black dots onto it (see print4.png). I haven't found any way of setting a pixel bitrate. 

 

In Flatten Pixmap help, it says "If you wire data to 24-bit pixmap, LabVIEW ignores this input." 

 

 

 

GerdW, tst

 

as I said I didn't set any color depth. How can I do that? I will write PNG instead of BMP though if you say it takes up less space. 

0 Kudos
Message 5 of 8
(4,290 Views)

@thehun wrote:

How can I set a picture to 4-bit or 1-bit?


The picture to pixmap VI which you call in print3 has a depth input, which determines which output of the VI will have the data. If it's 1, it will be the boolean array output. And yes, PNG should be smaller (definitely don't use JPEG, because that's lossy and not suitable for something like this).


___________________
Try to take over the world!
Message 6 of 8
(4,284 Views)

@tst wrote:

@thehun wrote:

How can I set a picture to 4-bit or 1-bit?


The picture to pixmap VI which you call in print3 has a depth input, which determines which output of the VI will have the data. If it's 1, it will be the boolean array output. And yes, PNG should be smaller (definitely don't use JPEG, because that's lossy and not suitable for something like this).



Thanks, for some reason I never realized about this input and it did the trick... partially.  The image looks pretty good (at the output of Draw Unflattened Pixmap VI) now but I'm getting an error when trying to save it as PNG:

 

Error 1 occurred at Check Color Table Size.vi

Possible reason(s):

@Labview: An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or


Complete call chain:
Check Color Table Size.vi
Write PNG File.vi
WBTB Main_12082015.vi

 

When I save it as BMP it doesn't throw any error and it "only" takes up 6.8 MB but the image is completely black. 

0 Kudos
Message 7 of 8
(4,253 Views)

Answering myself... instead of doing thing as I was I unflattened again the picture at the output of the Draw Unflattened Pixmap VI and fed this into the Write PNG File VI. It's working perfectly and only takes up 320kB Smiley Happy

0 Kudos
Message 8 of 8
(4,238 Views)