Poly2mask for large images
Show older comments
Hello,
I am trying to create a binary mask that is as large as the original image (107105 x 77377 pixels). I have all of the coordinates of the vertices of the ROI polygon and I want to use poly2mask for the binary mask. However, because the size is too large, MATLAB gave me this error.
Requested 107105x77377 (61.7GB) array exceeds maximum array size preference
(16.0GB). This might cause MATLAB to become unresponsive.
Is there anyway to use poly2mask with large matrices? I need the binary mask to be as big as the original image because the original image is split into tiles and I am trying to split the mask into tiles also. I thought of using a smaller version of the mask but I was afraid the minimization will affect the tile splitting process. Down here is a part of my code, smaller_x is the x coordinates and smaller_y is the y coordinates of the vertices. nrow and ncol are the size of the matrix, which are in turn 107105 and 77377.
mask = false(nrow,ncol);
mask = mask+poly2mask(smaller_x,smaller_y,nrow,ncol);
Answers (1)
Image Analyst
on 24 Apr 2022
0 votes
Wow, yes that is a very large image. You might look into memmapfile().
Or else see if you can process the image in smaller bite-size chunks.
Depending on what you want to do, it may be possible to get the same results by downsampling your image. For example if you want the area fraction of some foreground object, unless you have lots and lots of fine structures, you may arrive at the same area fraction processing a much smaller image. Maybe it would be only a fraction of a percent different and that may be accurate enough given the inherent variability in the objects in your scene.
Categories
Find more on Region and Image Properties in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!