Download this file

99 lines (72 with data), 2.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
% testing Deep Learning algorithms
clear all
clc
close all
addpath('functions');
% save('DL_ROI_params','stackedAEOptTheta','inputSize','hiddenSizeL1','hiddenSizeL2','outputSize','netconfig');
% save('DLconfigure/DL_LV_ES_params','stackedAEOptTheta','inputSize','hiddenSizeL1','hiddenSizeL2','outputSize','netconfig');
%%
% load images
load matFiles/validation_dataES;
patient=3;
%min_sn=sum(slice_per_patient(1:patient-1))+1;
min_sn=1;
max_sn=sum(slice_per_patient(1:patient-1))+slice_per_patient(patient);
slice_num=min_sn:max_sn;
% get dicom info
dicom_path=['dcom/validation/ED',num2str(patient),'/images'];
para=get_dicominfo(dicom_path);
% show plots or not
disp_ena=0;
% load parameters of Deep Learning for ROI
Mroi=100;
% load Deep learning paramenters for LV segmentation
load DLconfigure/DL_LV_ES_params.mat;
for k=1:length(slice_num)
%for k=1:size(t_Iroi,3)
C1=t_contours{k}; % read manual contours
m_cnt=t_centers{k}; % read centers
%subI=t_Iroi(:,:,k);
display(['processing slice# ',num2str(slice_num(k))])
subI=t_Iroi(:,:,slice_num(k));
% run Deep Learning network to find the segmentation of LV
t_yLV_h(:,:,k)=DLN(subI,stackedAEOptTheta,inputSize,hiddenSizeL1,hiddenSizeL2,outputSize,netconfig);
% clean segmentations
t_yLV_clean(:,:,k)=clean_segs(t_yLV_h(:,:,k));
% dice metric
[overlap, dice(k)]=DiceSimilarity2DImage(t_yLV_clean(:,:,k), t_yLV(:,:,k));
% resize to original image size
t_LVmask(:,:,k)=remap_mask(t_yLV_clean(:,:,k),t_centers{k},t_yROI(:,:,k));
autoPoints=contourc(double(t_LVmask(:,:,k)), [0 0]);autoPoints=autoPoints(:,2:end)';
% Perpendicular Distance
manualPoints=t_contours{slice_num(k)};
PD(k) = calc_dist(autoPoints,manualPoints,para);
end
%% dice metric
avg_dice=mean(dice)
perp_dis=mean(PD)
%% display images and contours
if disp_ena==1
% get number of studies
num_studies=length(slice_per_patient);
for k=1:num_studies
% get number of slices per patient
spp=slice_per_patient(k);
for k2=1:spp
% get manual contour file name
ind=k2+sum(slice_per_patient(1:k-1));
figure(k)
subplot(5,3,k2)
imagesc(t_Iroi(:,:,ind));colormap(gray);
hold on; contour(t_yLV_clean(:,:,ind),[0 0],'g','LineWidth',2);
contour(t_yLV(:,:,ind),[0 0],'r','LineWidth',2);
figure(num_studies+k)
subplot(5,3,k2)
imagesc(t_I(:,:,ind));colormap(gray);
hold on; contour(t_LVmask(:,:,ind),[0 0],'r','LineWidth',2);
plot(t_contours{ind}(:,1),t_contours{ind}(:,2),'g','LineWidth',2);
end
end
end
%% save contours as text files
% output=save_contours(t_LVmask,t_LV_cont_names,slice_per_patient);