clc;
clear all;
filepath = 'C:\Users\Lee\Desktop\gt\'; %图片路径可以根据自己需要修改;
ext='*.png';
dis=dir([filepath ext]);
names={dis.name};
a=imread([filepath names{1}]);
groundTruth = cell(1,length(names));
for k=1:length(names)
nm=[filepath names{k}];
image=imread(nm);
image_gray=rgb2gray(image); %输入的是三维图像,把它转为二维图像
groundTruth(:,k)=cell(1,1)
groundTruth(:,k){1,1}.Segmentation=uint16(image_gray)
groundTruth(:,k){1,1}.Boundaries=logical(image_gray)
end
save gt.mat groundTruth
以上是单张图片,多个标注的mat文件生成方式
下面是多张图片(每张图片)单个标注的mat文件生成方式:
clc;
clear all;
filepath = '\edges\edge_maps\test\rgbr\'; %图片路径可以根据自己需要修改;
savepth = '\edges\edge_maps\test\rgbr_mat\';
ext='*.png';
dis=dir([filepath ext]);
names={dis.name};
for k=1:length(names)
groundTruth = cell(1,1);
nm=[filepath names{k}];
image=imread(nm);
%person{1,1}.Segmentation=uint16(image_gray)
groundTruth{1,1}.Boundaries=logical(image);
S = strsplit(names{k}, '.');
savenm=[savepth S{1} '.mat']
save(savenm,"groundTruth")
end
再补充一个多图片(每张图片)多标签的
clc;
clear;
% edges_name = 'E:\CODE\pidinet-master-suzhuo\multicue_edge.txt';
% gt_dir = 'H:\00Dataset\multicue-dataset\multicue\ground-truth\images\edges\';
% sv_dir = 'H:\00Dataset\multicue-dataset\multicue\ground-truth\mat\edges\';
% % 打开txt文件
% fileID = fopen(edges_name, 'r');
boundaries_name = 'E:\CODE\pidinet-master-suzhuo\multicue_boundry.txt';
gt_dir = 'H:\00Dataset\multicue-dataset\multicue\ground-truth\images\boundaries\';
sv_dir = 'H:\00Dataset\multicue-dataset\multicue\ground-truth\mat\boundaries\';
% 打开txt文件
fileID = fopen(boundaries_name, 'r');
% 读取多行数据
data = textscan(fileID, '%s');
% 关闭文件
fclose(fileID);
data = data{1,1};
for j=1:length(data)
img_nm=strsplit(data{j},'.');
img_nm = img_nm{1,1};
%打开gt
files = dir(fullfile(gt_dir, '*.png')); % 根据需要修改文件类型
gtNames = cell(length(files), 1);
count = 0;
gt = cell(20);
for i = 1:length(files)
gtNames{i} = files(i).name;
if strfind(gtNames{i},img_nm)
count = count+1;
gt{count} = gtNames{i};
end
end