这个是参与研究生的左心分割项目,我所做的一些代码。这个项目目的就是为了自动识别左心轮廓,这个代码的作用就是将深度学习产生的预测以图片形式保存下来,然后人工修改预测不好的部分,作为标签,再用来产生模型。预测新的轮廓。
言归正传,以下是功能实现:
%有内外两轮廓以及原图,方法是把内外两轮廓覆盖到原图上,
clc;close all;clear;
path='F:\show_counter\matfile';
path=strrep(path,'\','/');
GEColormap=loadGEColormap();
B=cell(1,8);
%% show both
for i=1:8 %心肌灌注成像,每个病人又分为8个gate
for s=0:9 %每个gate又有10个slice
% get pred contour : ML contour 外
Seg_name=sprintf('epi/Patient002481_data_0%d_pred_0%d.mat',i,s);
%sprintf 拼接路径
workpath=fullfile(path,Seg_name);
load(workpath);
BW=bwboundaries(pred);
B{i}=BW{:}(:,:);
contour_path1=zeros(32,32);
iter=size(B{i},1);
for j=1:iter
contour_path1(B{i}(j,1),B{i}(j,2))=1;%contour_path1为DL产生的外轮廓
end
%内
Seg_name=sprintf('endo/Patient002481_data_0%d_pred_0%d.mat',i,s);
workpath=fullfile(path,Seg_name);
load(workpath);
BW=bwboundaries(pred);
B{i}=BW{:}(:,:);
contour_path2=zeros(32,32);
iter=size(B{i},1);
for j=1:iter
contour_path2(B{i}(j,1),B{i}(j,2))=1;
end
% get original image
Im_name=sprintf('epi/Patient002481_data_0%d_img_0%d.mat',i,s);
workpath=fullfile(path,Im_name);
load(workpath);
process_img=img.*(1-contour_path1);
ones=find(contour_path2==1);
process_img(ones)=0;
figure(i);
%subplot();
save_path=sprintf('test%d.png',s);
saveas(gca,save_path); %保存图片
R_process_img=rot90(process_img,1);
imagesc(R_process_img);
colormap(GEColormap);
axis off;