X
3816

How to work around RAM limits when making a mask from an ROI

When building a mask from an ROI in ENVI, you may receive an error message that says unable to allocate memory to make array. This message indicates that your system does not have enough RAM available to build a mask from the specified ROI. This help article describes how you can work around this RAM limitation and still make your desired mask in ENVI.

Making a mask from an ROI in ENVI can use a very large amount of RAM because the address for every pixel in the ROI must be read into memory before the mask can be built. The ROI pixel addresses are long integers, so each pixel in the ROI requires 4 bytes of memory. For large ROIs the required RAM can add up fast. Moreover, one continuous block of memory is required to store all of the addresses for the ROI - and this memory is in addition to that required to run ENVI, your operating system, and any other applications that you may have open.


Sometimes people are confused by the large RAM requirement when generating masks from ROIs, because they notice that when a polygon ROI is saved to a file in ENVI, the file is usually quite small. Keep in mind that ENVI ROI files store the addresses for only the polygon vertices, and not the addresses for all of the pixels inside the polygon. But when the ROI is converted to a mask, the address for each pixel in the ROI is calculated from the polygon vertices and stored in memory.

Fortunately, it is usually possible to avoiding building a mask from an ROI. Here are some alternative ways to build masks:

  1. If the ROI was generated using the Image Threshold to ROI tool, then you could make an equivalent mask by choosing Import Band Data Range from the Options menu of the Mask Definition dialog.

  2. If the ROI is a polygon, then it is possible to work around the problem by creating an annotation polygon that is the same shape as your ROI polygon, and importing the annotation into the Mask Definition dialog instead of the ROI. To bring up the annotation tool, go to the display Functions menu and choose Overlays -> Annotation. You will need to trace your annotation polygon over your ROI polygon, because it is not possible to convert an ROI polygon directly to an annotation polygon

Building a mask from an annotation polygon requires less RAM than building the mask from an ROI because the mask-building code uses IDL's POLYFILLV with the RUN_LENGTH flag set when working with annotation polygons. Therefore, an annotation polygon with millions of points will store only a few thousand run-length entries in RAM at one time. The run-length-encoded information is then used to fill the mask. The individual pixel addresses are never needed.