Hi Valentina,
The variables I and IOB is your program are large matrix whose data type is "double" by default which can cosume large amount of memory. Moreover, when the variable Ired is created, it contains a large number of such large matrices which consumes about 6154356278 Bytes after processing due to which the error occurs.
To resolve this issue,
- Try to process the roi in chunks for creating Ired.
- Use a smaller data types such as uint8 or single for I and IOB instead of double. This will reduce the memory consumption upto 8 times.
I=ones(640,640,1600, "uint8");
IOB=ones(640,640,1600, "uint8");
- Use the "whos" to check the memory usage of variables.
- Instead of manually finding the bounding box for cropping, you can use the regionprops function, which is more efficient for binary masks. It will give you the bounding box directly.
Please refer to the following documentation links to learn more about:
- Numeric Datatypes: https://www.mathworks.com/help/matlab/numeric-types.html
- whos : https://www.mathworks.com/help/matlab/ref/whos.html
- regionprops: https://www.mathworks.com/help/images/ref/regionprops.html
Hope this helps.
