LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to Double Some Images

I need to double some images.  This works:

di.png

but it runs out of memory with large images.

How can I do that differently so as to use less memory?

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 1 of 17
(1,864 Views)

I believe that the "Concatenate" output terminal plus a lot of the other array operations are creating a lot more memory allocations than you expect.

 

In order to minimize the allocation of memory, you could pre-allocate a new array big enough at the start, then use an in-place array element to put the elements in it individually, which guarantees no additional memory allocations.

 

There's probably a cleaner way to do this but here's an extremely ugly example:

Kyle97330_0-1676060369025.png

 

Message 2 of 17
(1,846 Views)

I forgot to mention that the memory overflow is happening inside "Flatten Pixmap.vi".

I recoded the snippet to double the image data without calling "Flatten Pixmap.vi"; and was able to successfully double the image at that point ...

But later on, I call "Write PNG File.vi"; and inside that, it calls "Flatten Pixmap.vi" which fails do to memory overflow.

I don't see any solution inside LabVIEW.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 3 of 17
(1,818 Views)

Hi Paul,


What resolution and bit depth images are you hitting memory issues with? I tried a 3500 x 2500 x 32-bit image with your snippet and it works under 32-bit LabVIEW.


Another option to reduce memory usage is to skip the methods for conversion to and from pixmap, and operate entirely on the 1D image array from the image data cluster. The attached snippet resizes the original image 2x, and works with an image array in 1 byte per pixel (256 color), 3 bytes per pixel (24-bit RGB), or 4 bytes per pixel (32-bit ARGB) format:

 

image-resize-2x_snippet.png

 

image-resize-2x.png

 

Depending on the image itself, another memory reduction option is to drop the image depth from 24-bit or 32-bit down to 8-bit, and then resize. I've written a LabVIEW library called G-Image which has some routines for reducing bit depth using quantization and dithering. It's not quite pngquant quality, but good enough for tasks involving LabVIEW front panels.

Message 4 of 17
(1,757 Views)

If all you are trying to do is resize an image, you can look into my Image Manipulation package over on VIPM.IO.  I just uploaded it and haven't had a chance to upload a demo video, but one of the functions is a GDI Resize that uses some .Net tools that Windows has.

 

https://www.vipm.io/package/hooovahh_image_manipulation/

Message 5 of 17
(1,707 Views)

@Hooovahh wrote:

If all you are trying to do is resize an image, you can look into my Image Manipulation package over on VIPM.IO.  I just uploaded it and haven't had a chance to upload a demo video, but one of the functions is a GDI Resize that uses some .Net tools that Windows has.

 

https://www.vipm.io/package/hooovahh_image_manipulation/


I was able to find a way to scale up the image, but when I try to save it as a .PNG, it runs out of memory because "Write PNG File.vi"; calls "Flatten Pixmap.vi" (which can't handle my large images).

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 6 of 17
(1,657 Views)

In that case you can get the PNG stream, then write that to disk with the normal file IO stuff.  Open the GDI Resize Image and near the end you will see it makes a MemoryStream of the image as a PNG.  This is an array of bytes that is turned into a string.  This string then goes into PNG Data to LV Image to return it as the Resized Image.  All you need to do is save that string (or the byte array) to a file and it should be your resized image.

 

I see the value in having the PNG image file be available as an optional output, that the user can save away.

0 Kudos
Message 7 of 17
(1,647 Views)

Exactly what sizes are you dealing with?

 

I have a faint recollection of a 'streaming' PNG 'library', used for a forum user that wanted to save circles (IIRC) in a nn000Xmm000 image. This is possible, the complete image never has to live in LabVIEW.

0 Kudos
Message 8 of 17
(1,645 Views)

wiebe@CARYA wrote:

Exactly what sizes are you dealing with?

 

I have a faint recollection of a 'streaming' PNG 'library', used for a forum user that wanted to save circles (IIRC) in a nn000Xmm000 image. This is possible, the complete image never has to live in LabVIEW.


Biggest one is about 1400 x 9400

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 9 of 17
(1,625 Views)

You can open Flatten pixmap.vi. There doesn't seem to be too much strange things going on. I think it'd be easier to use a couple of Split byte instead of those ANDs and shifts (like they do in the color to RGB functions.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 17
(1,610 Views)