|
a |
|
b/combinedDeepLearningActiveContour/display3D.m |
|
|
1 |
% read manual segmentation and generate a 3D plot |
|
|
2 |
clc |
|
|
3 |
close all |
|
|
4 |
clear all |
|
|
5 |
addpath('functions'); |
|
|
6 |
%% |
|
|
7 |
imset='training'; |
|
|
8 |
patient=1; |
|
|
9 |
%% read direcotory of images |
|
|
10 |
folder=['dcom/',imset,'/ED',num2str(patient),'/images']; |
|
|
11 |
[IMAGES, xthickness, ythickness, zthickness] = gatherImages(folder); |
|
|
12 |
|
|
|
13 |
[x_max,y_max,z_max]=size(IMAGES); |
|
|
14 |
% for k=1:z_max |
|
|
15 |
% subplot(3,5,k) |
|
|
16 |
% imagesc(IMAGES(:,:,k)); |
|
|
17 |
% colormap(gray); |
|
|
18 |
% end |
|
|
19 |
|
|
|
20 |
% adjust the resolution so that it falls in range [0-max_res] |
|
|
21 |
max_res=3; |
|
|
22 |
norm_res = floor(max(IMAGES(:))/(max_res)) ; |
|
|
23 |
Im = (IMAGES./norm_res); |
|
|
24 |
|
|
|
25 |
figure |
|
|
26 |
for k1=1:size(Im,3) |
|
|
27 |
I1=Im(:,:,k1); |
|
|
28 |
subplot(3,5,k1); |
|
|
29 |
imshow(I1); |
|
|
30 |
end |
|
|
31 |
%% read directory of contours |
|
|
32 |
current_dir=pwd; |
|
|
33 |
contour_dir=['dcom/',imset,'/ED',num2str(patient),'/contours/LV']; |
|
|
34 |
cd(contour_dir); |
|
|
35 |
dfile = dir('*.txt'); |
|
|
36 |
numFiles = size(dfile,1); |
|
|
37 |
|
|
|
38 |
% load contours |
|
|
39 |
for k=1:numFiles |
|
|
40 |
contours{k}=load (dfile(k,:).name); |
|
|
41 |
end |
|
|
42 |
cd(current_dir); |
|
|
43 |
|
|
|
44 |
% display images and contours |
|
|
45 |
for k=1:z_max |
|
|
46 |
figure (1) |
|
|
47 |
subplot(3,5,k) |
|
|
48 |
% show image |
|
|
49 |
I1=Im(:,:,k); |
|
|
50 |
imagesc(I1); |
|
|
51 |
colormap(gray); |
|
|
52 |
hold on |
|
|
53 |
|
|
|
54 |
% read contour |
|
|
55 |
C1=contours{k}; |
|
|
56 |
x1=floor(C1(:,1)); |
|
|
57 |
y1=floor(C1(:,2)); |
|
|
58 |
plot(x1,y1,'r'); |
|
|
59 |
|
|
|
60 |
% creat segmentation mask |
|
|
61 |
figure (2) |
|
|
62 |
subplot(3,5,k) |
|
|
63 |
% note that row==y and column==x |
|
|
64 |
LV_seg(:,:,k)=accumarray([y1 x1],1,[y_max x_max]); |
|
|
65 |
imagesc(LV_seg(:,:,k)); |
|
|
66 |
colormap(gray) |
|
|
67 |
title('segmnetation mask') |
|
|
68 |
end |
|
|
69 |
|
|
|
70 |
%% find edges of segmentation contours |
|
|
71 |
for k=1:size(Im,3) |
|
|
72 |
figure(3); |
|
|
73 |
subplot(3,5,k); |
|
|
74 |
%Find edges in intensity image |
|
|
75 |
edge_seg = edge(LV_seg(:,:,k)); |
|
|
76 |
imshow(Im(:,:,k) -2*edge_seg); |
|
|
77 |
title('edges') |
|
|
78 |
end |
|
|
79 |
%% show three dimensional patch |
|
|
80 |
figure |
|
|
81 |
phi = LV_seg(:,:,end:-1:1); |
|
|
82 |
p3 = patch(isosurface(phi, 0), 'FaceColor','red', 'EdgeColor','none'); |
|
|
83 |
isonormals(phi,p3) |
|
|
84 |
zlabel('z','FontSize',10,'FontWeight','bold'); |
|
|
85 |
box on ; alpha(.6) |
|
|
86 |
xrange = []; |
|
|
87 |
yrange = []; |
|
|
88 |
|
|
|
89 |
axis([1 size(phi,2) 1 size(phi,1) 1 size(phi,3)]) |
|
|
90 |
set(gca,'YTick',yrange,'fontsize',8) |
|
|
91 |
set(gca,'XTick',xrange,'fontsize',8) |
|
|
92 |
set(gca,'ZTick',round(10:size(phi,3)/5:size(phi,3)), 'fontsize',8) |
|
|
93 |
|
|
|
94 |
hold on |
|
|
95 |
colormap(gray); |
|
|
96 |
dimz=size(Im,3); |
|
|
97 |
for k1=1:3:dimz |
|
|
98 |
|
|
|
99 |
Img2D_CrossSection = Im(:,:,k1); |
|
|
100 |
xImage = [1 size(phi,2); 1 size(phi,2)]; %# The x data for the image corners |
|
|
101 |
yImage = [1 1 ; size(phi,1), size(phi,1)]; %# The y data for the image corners |
|
|
102 |
zImage = k1 * ones(2,2); %# The z data for the image corners |
|
|
103 |
surf(xImage,yImage,zImage,... %# Plot the surface |
|
|
104 |
'CData',Img2D_CrossSection ,... |
|
|
105 |
'FaceColor','texturemap'); |
|
|
106 |
end |
|
|
107 |
% viewpoint spec: view(az,el) |
|
|
108 |
view(-30,13) |
|
|
109 |
|
|
|
110 |
axis tight |
|
|
111 |
camlight |
|
|
112 |
camlight(-80,-10) |
|
|
113 |
lighting gouraud |