LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

cluster with images: memory increases to over 2 gb and crashes

Solved!
Go to solution

I have bunch of PNG images (about 1200, 12 mb on size) and I load them programatically into labview with a for loop. I put all the image data into an array for all the images.

I cant finish this operation, while the images are very small LV memory is increasing to over 2 gb and then I get an out of memory error.

I have put an 'in place structure' over all array operations. What's going on? Im definately doing something wrong I guess.

 

 

 

0 Kudos
Message 1 of 10
(2,891 Views)

When I split it up and write a datalog of the cluster I get 1 gb files. When I compress is using 7zip I am back at my original 12 mb. So labview makes 12mb into 1 gb

0 Kudos
Message 2 of 10
(2,888 Views)

Hi Faust,

 

- how are you loading the images? Using "Picture" functions or using IMAQ?

 

- How big are your PNG pictures (in pixel)? do they use 24bit color depth?

 

Let's do some calculation:

640*480 pixel = 307200 pixel

3 byte/ pixel => 921600 byte/picture

1200 pictures => 1105920000 byte ~= 1055 MiB (just for the picture data)

 

Edit:

PNG uses compression. LabVIEW doesn't use compression for picture data in memory.

How much grows a PNG file when converted to BMP? They same ratio applies when loading them in LabVIEW...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 10
(2,887 Views)

Gerd,

 

Thanks for the help. I'm using png because I need transparancy. The images are used for an animation.

Is there a way to keep some sort of compression or keep the size down another way. I preferably have the images in memory

due to slow read-from-disk operations.

 

About the image qualities, they are 32 bit and 850 by 360 pixels BUT about 99% is transparant (The images has a constant size which is transparant, there is a small object that moves in this space).

 

 

0 Kudos
Message 4 of 10
(2,872 Views)

by the way, I use the 'read png' function.

Seems we need to look for another solution. Your calculation is about right. Any suggestions?

 

 

Thanks!

0 Kudos
Message 5 of 10
(2,871 Views)
Solution
Accepted by topic author _Faust

Hi Faust,

 

"About the image qualities, they are 32 bit and 850 by 360 pixels BUT about 99% is transparant (The images has a constant size which is transparant, there is a small object that moves in this space)."

 

Transparency is irrelevant in terms of memory occupation.When the picture is loaded it simply needs 850*360*4bytes (or ~1.2 MB)...

 

Suggestion:

- Don't hold all pictures in memory... Do the calculation in slices of (let's say) 100 pics.

- Do some image manipulation to get the position of the moving object. Then you only store a small portion of the picture (with the object) and some information on the location in the picture. That way you still know the size of the (original) pic, but you only keep the 'interesting' part in memory!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 10
(2,856 Views)

How are you putting them into the array? I hope you are not using build array. It is good practice to initialize an array then replace the elements in a loop. This is especially true for what you are doing.

=====================
LabVIEW 2012


Message 7 of 10
(2,852 Views)

Thanks guys.

I'm not explicitly putting into an array; I have for loop running with indexing enabled.

 

Could you explain why it is better to replace array elements instead of building? speed?

Maybe something to keep in mind for other processes.

 

0 Kudos
Message 8 of 10
(2,833 Views)

I'll go with GerdW's solution by the way. Thank you all again for your input and help!

0 Kudos
Message 9 of 10
(2,831 Views)

When you preallocate an array then LabVIEW knows how much memory to allocate for it. Replacing an element does not require another memory resize. When you use build array then LabVIEW needs to find another memory block for the result. This can cause an exponential slowdown.

 

If you have indexing enabled on the array output of your for loop then if you wire to the N terminal LabVIEW will know how much memory to allocate in advance.

 

This brings up an interesting question that I will post separately.

=====================
LabVIEW 2012


Message 10 of 10
(2,824 Views)