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