[GIS] What’s the binary format of ENVI (Classic) ROIs

envifile formatspython

I'm a Pythonist in an office full of ENVI/IDL users. I've created some tools to help bridge the gap, but one big stumbling block is ENVI Classic .roi files, which my colleagues use a lot.

I can easily import ENVI 5 ROIs into Python, since the text-based format is easy to parse. However, I don't have a good sense for the binary format of ENVI Classic .roi files, which make up the bulk of data interchange in my group. Does anyone have any code that reads or writes these files, or any insight on how one might go about it?

It's somewhat tedious to fire up ENVI 5 every time I want to go back and forth – I'd rather solve the problem at the source if possible.

Best Answer

I'm no python expert, but this should be relatively easy to do if you're already writing scripts that can parse, read, and write standardized ASCII files.

According to Harris Geospatial Solutions, the current developer of ENVI, ENVI binary image files (described here) should consist of the binary file and an ASCII header file (defined with example here). To read an ENVI image file, you'll need to parse the ASCII header and access the data type (integer, float, signed/unsigned, etc.), number of bands, the interleave (Band Sequential, Band-interleaved-by-pixel, or Band-interleaved-by-line), byte order, and any other pertinent data information. Take a close look at the header file format description and example linked to above.

Now that you know what chunks of the binary to read at a time, what order they are in, and which bands they belong to, you're ready to read the image data.