方法1: 直接使用ENVI
-
step1: 将roi文件存储为.roi格式
[1] 链接: link
-
step2: 将.roi转为mask
[2] 链接: link
[3] 链接: link
方法2: 使用Matlab
-
step1: 将roi文件存储为.xlm 文件
-
step2:针对把每个roi存储为一个单独文件
[4] 读取xlm文件: link
[5] 生成mask:link -
.xlm文件示例:红括号内是一个点的坐标(x,y)
- matlab code
% 1. Define inputfile and output folder
fn1 = './input.xml';
dirout1 ='/mask_folder/'% 2. Read .xlm file
T = readtable(fn1);% 3. Check variable name
% opts = detectImportOptions(fn1);
% var_name = opts.VariableNames.'% 4. Read coordinate
Coor = T.Coordinates;
Coor_list = {}
for i = 1: size(Coor,1)Coor_newStr = split(Coor(i),' '); % read the coordinate for j=1: length(Coor_newStr)/2idx0 = 2*j-1;idx1 = 2*j;X_list(j) = str2num(Coor_newStr(idx0)); % convert str to numberY_list(j) = str2num(Coor_newStr(idx1)); % convert str to numberclear idx0 idex1;end Coor_list{i}= [X_list;Y_list];clear X_list Y_list;end % 5. Creat mask base on roi and save as png
% 1: 多边形的值
% 0: 无效值
for i = 1: length(Coor_list)bw = poly2mask(Coor_list{i}(1,:),Coor_list{i}(2,:),weight,width);%imwrite(bw,strcat(dirout1,'ROI_',num2str(i,'%03.f'),'.png'),'png');clear bw;end
Other reference
[1] Python convert roi to mask: link
[2] IDL READENVIROI - Read ENVI files: link