File Exchange

image thumbnail

ENVI ROI File Reader

version 1.2.0.0 (3.35 KB) by Jared
Reads in ROI files from ENVI saved in ASCII format

1 Download

Updated 15 Jun 2012

View License

This script reads ROI files from ENVI by Exelis (Formerly ITT) DataVis into Matlab. It outputs a Struct to your Matlab session containing the ROIs by name and associated information according the the ROI file header. For each ROI, the struct includes the ROI name, color, number of points, and the ROI point matrix. The script assumes the ROI file is in ASCII and follows a strict formatting. Please comment as you see fit as this is the first submission and I expect there will need to be updates. This script was written using Matlab version 7.8.0.347 (R2009a)

Cite As

Jared (2020). ENVI ROI File Reader (https://www.mathworks.com/matlabcentral/fileexchange/27492-envi-roi-file-reader), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (7)

zheng li

Thank you for the job you have done .But I meet a problem when I use it, It’s busy all the time, and can’t output the result. Does someone have some advice for this problem? Thanks!

florrieee

Hi,
ROIsRecordsTmp = regexp(fline,'\s{2,}','split'); can not correctly count the number when band>=100, the spacing is 1 instead of 2 after that.

The 'naive' solution to this is:
ROIsRecordsTmp = regexp(fline,'\s{1,}','split');
and change:
NumRecords = length(ROIs.Records) - 2;

hdchina2010

Great to find a way can read envi roi file directly, but seem the function doesn't work well on my PC (ENVI 4.8 and Matlab R2014a). It's busy all the time, hope this can be fixed soon and hope can add the feature of writing matlab roi etc. to ENVI roi.
Thank you.

Hi Jared,

Running this function with a .roi file as the argument returns the following error on Matlab 2013a -

>> imstruct = roiRead('TR2.roi')
Error using fgets
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in fgetl (line 36)
[tline,lt] = fgets(fid);

Error in roiRead (line 82)
fline = fgetl(fid);

Any clue if this is because of newer Matlab version?

Jared

I should have mentioned above, that I just submitted the file to Matlab Exchange, so the file could take up to 5 business days from the date of this post to actually appear for download. So if the file isn't appearing yet, please be patient.

Jared

I updated the code to handle Lat and Long coordinates in an ROI file. Thanks to Yang Li of Beijing Normal University in China for his suggestions on the code.

I haven't written the code to take the points from the ROI struct in Matlab and write them to an ENVI ready text file. Good suggestion though.

Yasser m

I wish it could work backward too: converting a matlab text file into envi roi.

Updates

1.2.0.0

Added capability to account for extra lines included in ROI files when saved using a Windows Operating system.

1.1.0.0

Updated code to handle ROI files from geo-tagged imagery (Lat and Long of ROI points). Also updated the readability fo the code.

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux