Borrar filtros
Borrar filtros

How to optimize image cropping?

15 visualizaciones (últimos 30 días)
Valentina
Valentina el 19 de Feb. de 2024
Respondida: Milan Bansal el 12 de Sept. de 2024 a las 7:02
I have a problem with this function 'Crop_sample', inside the 'I_reduction1' function. I got 'out of memory'. I need to optimize it, but I don't know what tools I could use. So, the function crops the mask, I, and IOB matrices based on the region of interest found in the input mask, and returns the cropped versions of these matrices as new_mask, new_I, and new_IOB, respectively. These cropped matrices will have dimensions determined by the size of the region of interest within the input mask. Given the additional information that I and IOB are matrices of dimensions 640x640x1600. Please help me. Maybe with some Image Processing Toolbox would be better, but I tried and nothing works.
I=ones(640,640,1600);
IOB=ones(640,640,1600);
load mask.mat;
Ired= I_Reduction1(roi1, I, IOB);

Respuestas (1)

Milan Bansal
Milan Bansal el 12 de Sept. de 2024 a las 7:02
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:
Hope this helps.

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by