02-10-2023 01:31 PM
I need to double some images. This works:
but it runs out of memory with large images.
How can I do that differently so as to use less memory?
02-10-2023 02:20 PM
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:
02-10-2023 03:49 PM
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.
02-13-2023 02:42 AM
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:
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.
02-13-2023 01:50 PM
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/
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
02-14-2023 07:28 AM
@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).
02-14-2023 08:12 AM - edited 02-14-2023 08:14 AM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
02-14-2023 08:13 AM
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.
02-14-2023 09:10 AM
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
02-14-2023 10:40 AM
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.