|
a |
|
b/Thoracic Organs Segmentation code/Main.m |
|
|
1 |
%Before .m execution add paths |
|
|
2 |
Path1= cd; Path1=[Path1,'\OpticalFlow3D'];path(Path1,path); |
|
|
3 |
Path1 = cd; Path1 = [Path1, '\MAP']; path(Path1, path); |
|
|
4 |
Path1 = cd; Path1 = [Path1, '\TwoPhaseLevel Sets']; path(Path1, path); |
|
|
5 |
|
|
|
6 |
%input images |
|
|
7 |
%Inhale and Exhale images |
|
|
8 |
load InhaleImg.mat;load ExhaleImg.mat; |
|
|
9 |
|
|
|
10 |
% InhaleImg=imresize(imread('InhaleImg.jpg'),0.3); |
|
|
11 |
% ExhaleImg=imresize(imread('ExhaleImg.jpg'),0.3); |
|
|
12 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
|
13 |
Img=reshape([InhaleImg;ExhaleImg]',[size(ExhaleImg,2),size(InhaleImg,1),2]); |
|
|
14 |
|
|
|
15 |
%Rib Cage Approximation |
|
|
16 |
Thresh = Histogr(Img); |
|
|
17 |
|
|
|
18 |
|
|
|
19 |
%MaxValue=max(max(max(Img))); |
|
|
20 |
%Img = rescalingFunction(Img,0.16*MaxValue,MaxValue); |
|
|
21 |
|
|
|
22 |
[RibCage]=RibCageApproximation(Img(:,:,1),Thresh); |
|
|
23 |
|
|
|
24 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
|
25 |
|
|
|
26 |
%Feature extraction |
|
|
27 |
|
|
|
28 |
%Optical Flow for the desplacement estimation |
|
|
29 |
i1= permute(squeeze(Img(:,:,1)),[1 2 3]);%Inhale Img |
|
|
30 |
i2= permute(squeeze(Img(:,:,2)),[1 2 3]);%Exhale Img |
|
|
31 |
Displacement = OpticalFlow3D(i1,i2); |
|
|
32 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
|
33 |
% Maximum likelikehood pixel to belong Heart. |
|
|
34 |
[J,I] = MaxLikelihood(Img(:,:,1),RibCage,squeeze(Displacement)); |
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
InnerCurve = DrawCircle(4,I(1),J(1),size(Img,1),size(Img,2),1); |
|
|
39 |
|
|
|
40 |
%Level Sets Process |
|
|
41 |
[phi1,phi2]=TwoPhasesLevelSet(Img(:,:,1),RibCage,InnerCurve); |
|
|
42 |
|
|
|
43 |
figure |
|
|
44 |
imshow(Img(:,:,1),[]); hold on |
|
|
45 |
c1 = contour(phi1,[0 0],'r','LineWidth',2.2); |
|
|
46 |
c2 = contour(phi2,[0 0],'g','LineWidth',2); |
|
|
47 |
title('Zero Level Set') |
|
|
48 |
hold off; |
|
|
49 |
|
|
|
50 |
|
|
|
51 |
[I_heart]=find((phi2)<=0); |
|
|
52 |
[I_lung]=find((phi1)<=0); |
|
|
53 |
|
|
|
54 |
SegmentOfThorax= zeros(size(Img)); |
|
|
55 |
SegmentOfThorax(I_heart)=1; |
|
|
56 |
SegmentOfThorax(I_lung)=1; |
|
|
57 |
SegmentOfThorax= imfill(SegmentOfThorax); |
|
|
58 |
|
|
|
59 |
figure(1) |
|
|
60 |
imshow(Img(:,:,1),[]); hold on |
|
|
61 |
c = contour(SegmentOfThorax,[0 0],'m','LineWidth',2); |
|
|
62 |
hold off |
|
|
63 |
|
|
|
64 |
|