Image acquisition toolbox: Predict how many imgs can be buffered in RAM?
Show older comments
Hello,
I am looking for a way to predict how many frames (approx.) I can capture to the RAM of my computer using the image processing toolbox. I would prefer this over logging to HD.
Is that somehow possible by knowing the size of a frame and knowing the free memory (how...?) Thank you!!
Error event occurred at 14:17:15 for video input object: Mono8-gentl-1.
Unable to allocate memory for an incoming image frame due to insufficient free physical memory.
Accepted Answer
More Answers (1)
Siraj
on 28 Sep 2023
Hi!
I understand that you would like to determine the maximum number of images you can load into MATLAB's memory without encountering insufficient free physical memory. You are seeking a way to predict this limit beforehand.
Based on my understanding, accurately determining the exact number of images that can be loaded into MATLAB's memory is challenging. However, you can use the "whos" function to find the size of a single image and then divide the "MemAvailableAllArrays" by the memory required by one image. This will give you an approximate number of images that can be loaded. Keep in mind that this approach does not account for the processing overhead that may consume additional memory when loading images into MATLAB.
To learn more about the "whos" function in MATLAB, you can refer to the following link:
Refer to the following code for better understanding.
% Read an image into MATLAB
image = imread("Images/random_image_01.png");
% Get the memory usage of the image
image_memory = whos("image").bytes;
% Check the available memory
[user,sys] = memory;
% Calculate the approximate number of images that can be loaded
num_of_images = user.MemAvailableAllArrays / image_memory
Additionally, I suggest trying the following suggestions to see if you can load your entire dataset without exhausting the available memory:
Check that the Java Heap Memory is not set to a very large value because that might restrict the amount of memory available to perform computations.
I recommend using an "ImageDatastore" object when dealing with a large collection of images that may not fit entirely in memory. The "ImageDatastore" object allows you to efficiently work with image data by loading and processing images in batches.
To learn more about the "ImageDatastore" object and its functionality in MATLAB, you can refer to the following link:
Hope this helps.
Categories
Find more on Matrox Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!