目标:利用Matlab进行图片的ROI标注,并保存。
Matlab代码:
clc
clear all;
close all;
%% open a picture
[filename, filepath] = uigetfile({'*.jpg;*.ppm; jpeg *.;*.bmp;*.png'},'Choose Input Image');
if isequal(filename,0) || isequal(filepath,0)
disp('User pressed cancel')
return
else
fullfp = fullfile(filepath, filename);
end
image = imread(fullfp); %代表要处理的图像
figure(1),imshow(image);
%% handle the picture
[A,rect] = imcrop(image);%根据rect确定:在原图中绘制的矩形的坐标,注意rect的格式[m n l k]->[(m,n) (m+l,n+k)]->[(n,m) (n+k,m+l)]
seg = imcrop(image,rect);%截取矩形区域图像并保存
figure(2),imshow(seg);
%% save the segImg
[Outputfilename, Outputfilepath] = uiputfile({'*.jpg','JPG files';'*.bmp','BMP files'},'Pick an Image');
if isequal(Outputfilename,0) || isequal(Outputfilepath,0)
return;
else
outfullfp = fullfile(Outputfilepath, Outputfilename);
end
imwrite(seg,outfullfp);
%% save the segImg
% outpath1 = 'C:\Users\Zhangwei\Desktop\合肥数据库图片\IDP数据库\IDP人工标记数据库\分割数据总库1';
%
% num=input('input a number:');
% imwrite(seg,strcat(outpath1,'\',strtok(filename,'.'),'_',num2str(num),'.jpg'));
% close all;
%% save transX of each image
% outpath2 = 'C:\Users\Zhangwei\Desktop\合肥数据库图片\IDP数据库\IDP人工标记数据库\偏移参数集';
% if (exist(strcat(outpath2,'\',strtok(filename,'.'),'.txt'))==0)
% fopen(strcat(outpath2,'\',strtok(filename,'.'),'.txt'),'wt');%在指定路径中打开一个txt文本
% fid = fopen(strcat(outpath2,'\',strtok(filename,'.'),'.txt'),'w');
% fprintf(fid,'%g\t',transX);
% fclose(fid);
% else
% data = textread(strcat(outpath2,'\',strtok(filename,'.'),'.txt'));
% data = data(1,1:end-1);
% dataSet = [transX data];
% fid = fopen(strcat(outpath2,'\',strtok(filename,'.'),'.txt'),'w');
% fprintf(fid,'%g\t',dataSet);
% fclose(fid);
% end
运行效果: