|
a |
|
b/combinedDeepLearningActiveContour/LV_single_slice.m |
|
|
1 |
% two-dimensional segmenter combined with Deep Learning |
|
|
2 |
clear all |
|
|
3 |
close all |
|
|
4 |
clc |
|
|
5 |
addpath('functions') |
|
|
6 |
|
|
|
7 |
%% load the image |
|
|
8 |
disp('Load MRI images'); |
|
|
9 |
imset='training'; |
|
|
10 |
%imset='online'; |
|
|
11 |
%imset='validation'; |
|
|
12 |
name1=['matFiles/',imset,'_data']; |
|
|
13 |
load (name1) |
|
|
14 |
%% |
|
|
15 |
patient=2; |
|
|
16 |
min_sn=sum(slice_per_patient(1:patient-1))+1; |
|
|
17 |
max_sn=sum(slice_per_patient(1:patient-1))+slice_per_patient(patient); |
|
|
18 |
step1=ceil((max_sn-min_sn)/5); |
|
|
19 |
sn_range=min_sn:step1:max_sn; |
|
|
20 |
slice_num=sn_range(4); |
|
|
21 |
%slice_num=110; |
|
|
22 |
|
|
|
23 |
% maximum iteration of active contour |
|
|
24 |
max_its = 150; |
|
|
25 |
intEweight=0.5; |
|
|
26 |
DLweight=0.1; |
|
|
27 |
Dynamic_Window=0; |
|
|
28 |
|
|
|
29 |
% enable plots |
|
|
30 |
dis_ena=1; |
|
|
31 |
|
|
|
32 |
% region of interest size |
|
|
33 |
Mroi=100; |
|
|
34 |
|
|
|
35 |
% get dicom info |
|
|
36 |
dicom_path=['dcom/validation/ED',num2str(patient),'/images']; |
|
|
37 |
para=get_dicominfo(dicom_path); |
|
|
38 |
|
|
|
39 |
|
|
|
40 |
display(['processing slice# ',num2str(slice_num)]) |
|
|
41 |
I=t_I(:,:,slice_num); |
|
|
42 |
|
|
|
43 |
% cut ROI from the image |
|
|
44 |
subI=t_Iroi(:,:,slice_num); |
|
|
45 |
|
|
|
46 |
% changing the size of the ROI if we want, useful for apex slices |
|
|
47 |
roi_x=round((size(subI,1)-Mroi)/2)+1:round((size(subI,1)+Mroi)/2); |
|
|
48 |
roi_y=round((size(subI,2)-Mroi)/2)+1:round((size(subI,2)+Mroi)/2); |
|
|
49 |
subI2(:,:,slice_num)=subI(roi_y,roi_x); |
|
|
50 |
m_cnt=t_centers{slice_num}; |
|
|
51 |
|
|
|
52 |
% run DL-LV segmentation to get phi_0 |
|
|
53 |
load DLconfigure/DL_LV_params.mat; |
|
|
54 |
DL_prms_fn='DLconfigure/DL_LV_params.mat'; |
|
|
55 |
init_mask1=DLN(subI2(:,:,slice_num),stackedAEOptTheta,inputSize,hiddenSizeL1,hiddenSizeL2,outputSize,netconfig); |
|
|
56 |
init_mask2=clean_segs(init_mask1); |
|
|
57 |
init_mask(:,:,slice_num)=remap_mask(init_mask2,size(subI)/2+1,subI); |
|
|
58 |
|
|
|
59 |
|
|
|
60 |
% run segmentation |
|
|
61 |
[LV_seg1,phi,m_cnt] = region_seg_subPhi(I,subI2(:,:,slice_num),m_cnt,init_mask1,max_its,intEweight,DLweight,Dynamic_Window,0,DL_prms_fn); |
|
|
62 |
LV_seg2=clean_segs(LV_seg1); |
|
|
63 |
out_mask = remap_mask(LV_seg2,size(subI)/2+1,subI); |
|
|
64 |
LV_seg(:,:,slice_num)=out_mask; |
|
|
65 |
|
|
|
66 |
% compute metrics |
|
|
67 |
manualPoints=t_contours{slice_num}; |
|
|
68 |
[dm1,dm2,PD1,PD2,HD1,HD2]=eval_metrics(I,m_cnt,LV_seg(:,:,slice_num),manualPoints,para); |
|
|
69 |
|
|
|
70 |
% special care for slices with large Perp Distance |
|
|
71 |
if PD2>= 3 |
|
|
72 |
edited_seg=edit_prior_shape(subI2(:,:,slice_num),LV_seg(:,:,slice_num),0); |
|
|
73 |
[dm11,dm22,PD11,PD22,HD11,HD22]=eval_metrics(I,m_cnt,edited_seg,manualPoints,para); |
|
|
74 |
if PD22<PD2 |
|
|
75 |
dm1=dm11;dm2=dm22;PD1=PD11;PD2=PD22;HD1=HD11;HD2=HD22; |
|
|
76 |
LV_seg(:,:,slice_num)=edited_seg; |
|
|
77 |
end |
|
|
78 |
end |
|
|
79 |
|
|
|
80 |
|
|
|
81 |
%% evaluate segmentations |
|
|
82 |
DM1=dm1 |
|
|
83 |
DM2=dm2 |
|
|
84 |
|
|
|
85 |
|
|
|
86 |
%% show only one slice |
|
|
87 |
|
|
|
88 |
C1=t_contours{slice_num};Ct=scaleContour(C1,t_centers{slice_num},100); |
|
|
89 |
stn=[imset,':patient:',num2str(patient),' slice:',num2str(slice_num)]; |
|
|
90 |
|
|
|
91 |
figure |
|
|
92 |
showCurveAndPhi(t_Iroi(:,:,slice_num),Ct ,(LV_seg(:,:,slice_num)), slice_num); |
|
|
93 |
ylabel(stn); |
|
|
94 |
|
|
|
95 |
figure |
|
|
96 |
showCurveAndPhi(t_Iroi(:,:,slice_num),Ct ,bwconvhull(LV_seg(:,:,slice_num)), slice_num); |
|
|
97 |
ylabel(stn); |
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|