%手动分割图,得到二值金标准
clear;
[filename,pathname]=uigetfile('*.bmp;*.png;*.jpg','pick picture file','MultiSelect', 'on');
resp = pathname(1:end-1);resp = [resp,'_truth'];
if ~exist(resp,'dir'),mkdir(resp); end
if isa(filename,'char')
file{1}=filename; ncount = 1;
else
file=filename; ncount = size(filename,2);
end
%边缘勾勒操作
for k = 1:ncount
str = fullfile(pathname,file{k});
im = imread(str);
figure(1);imshow(im,[]);
h=imfreehand(gca); %交互式自由勾勒肿瘤轮廓
wait(h); %等待双击确定勾勒的轮廓
%如果没画好轮廓,右键删除后,重新获取句柄勾勒
while(~isvalid(h)) %判断句柄是否被删除(找了好多种方式才找到的)
h=imfreehand(gca);
wait(h);
end
bw=createMask(h);
name=[file{k}(1:end-4),'.mat'];
save(fullfile(resp,name),'bw');
% imwrite(bw,fullfile(newImgpath,file{k})); 不能保存成图片,会变成uint8类型,像素值改变
end