|
a |
|
b/Thoracic Organs Segmentation code/TwoPhaseLevel Sets/fillingProc.m |
|
|
1 |
%function [finalImg]=fillAorta(i,j,aortaValue,filteredImg) |
|
|
2 |
%function finalImg=fillAorta(i,j,filteredImg,inputImg) |
|
|
3 |
function finalImg = fillingProc(centre_i,centre_j,filteredImg); |
|
|
4 |
|
|
|
5 |
|
|
|
6 |
%maxPixelValue=250; |
|
|
7 |
setValue=1;%max(max(filteredImg)); |
|
|
8 |
finalImg=zeros(size(filteredImg)); |
|
|
9 |
|
|
|
10 |
%threshold choice |
|
|
11 |
threshold=1;%max(max(filteredImg));%mean(mean(filteredImg)); |
|
|
12 |
|
|
|
13 |
centre_i=centre_i; |
|
|
14 |
centre_j=centre_j; |
|
|
15 |
|
|
|
16 |
stack=-ones(255^2,2); |
|
|
17 |
stack_index=1; |
|
|
18 |
stack(stack_index,1)=centre_i; |
|
|
19 |
stack(stack_index,2)=centre_j; |
|
|
20 |
i=centre_i;j=centre_j; |
|
|
21 |
while(stack_index>0 )%&& j+1<size(filteredImg,1) && j-1>0 && i+1<size(filteredImg,2) && i-1>0) |
|
|
22 |
%oldValue=finalImg(pixel_i,pixel_j); |
|
|
23 |
i=stack(stack_index,1); |
|
|
24 |
j=stack(stack_index,2); |
|
|
25 |
stack_index=stack_index-1; |
|
|
26 |
finalImg(i,j)=setValue; |
|
|
27 |
|
|
|
28 |
%if( checkNeighbour(filteredImg(i,j),filteredImg(i,j+1))==1 && finalImg(i,j+1)~=setValue ) |
|
|
29 |
if(j+1<=size(filteredImg,2)) |
|
|
30 |
if( finalImg(i,j+1)~=setValue) |
|
|
31 |
|
|
|
32 |
if( checkNeighbour(filteredImg(i,j),filteredImg(i,j+1),threshold)==1 ) |
|
|
33 |
stack_index=stack_index+1; |
|
|
34 |
stack(stack_index,1)=i; |
|
|
35 |
stack(stack_index,2)=j+1; |
|
|
36 |
else |
|
|
37 |
finalImg(i,j+1)=setValue; |
|
|
38 |
end |
|
|
39 |
|
|
|
40 |
end |
|
|
41 |
end |
|
|
42 |
|
|
|
43 |
%if( checkNeighbour(filteredImg(i,j),filteredImg(i,j-1))==1 && finalImg(i,j-1)~=setValue ) |
|
|
44 |
if (j-1>0) |
|
|
45 |
if( finalImg(i,j-1)~=setValue) |
|
|
46 |
|
|
|
47 |
if( checkNeighbour(filteredImg(i,j),filteredImg(i,j-1),threshold)==1 ) |
|
|
48 |
stack_index=stack_index+1; |
|
|
49 |
stack(stack_index,1)=i; |
|
|
50 |
stack(stack_index,2)=j-1; |
|
|
51 |
%fillAorta(i,j-1); |
|
|
52 |
else |
|
|
53 |
finalImg(i,j-1)=setValue; |
|
|
54 |
end |
|
|
55 |
end |
|
|
56 |
end |
|
|
57 |
|
|
|
58 |
%if( checkNeighbour(filteredImg(i,j),filteredImg(i+1,j))==1 && finalImg(i+1,j)~=setValue ) |
|
|
59 |
if (i+1<=size(filteredImg,1)) |
|
|
60 |
if( finalImg(i+1,j)~=setValue ) |
|
|
61 |
|
|
|
62 |
if( checkNeighbour(filteredImg(i,j),filteredImg(i+1,j),threshold)==1 ) |
|
|
63 |
stack_index=stack_index+1; |
|
|
64 |
stack(stack_index,1)=i+1; |
|
|
65 |
stack(stack_index,2)=j; |
|
|
66 |
%fillAorta(i+1,j) |
|
|
67 |
else |
|
|
68 |
finalImg(i+1,j)=setValue; |
|
|
69 |
end |
|
|
70 |
|
|
|
71 |
end |
|
|
72 |
end |
|
|
73 |
|
|
|
74 |
%if( checkNeighbour(filteredImg(i,j),filteredImg(i-1,j))==1 && finalImg(i-1,j)~=setValue ) |
|
|
75 |
if (i-1>0) |
|
|
76 |
if( finalImg(i-1,j)~=setValue ) |
|
|
77 |
|
|
|
78 |
if( checkNeighbour(filteredImg(i,j),filteredImg(i-1,j),threshold)==1 ) |
|
|
79 |
stack_index=stack_index+1; |
|
|
80 |
stack(stack_index,1)=i-1; |
|
|
81 |
stack(stack_index,2)=j; |
|
|
82 |
%fillAorta(i-1,j) |
|
|
83 |
else |
|
|
84 |
finalImg(i-1,j)=setValue; |
|
|
85 |
end |
|
|
86 |
end |
|
|
87 |
|
|
|
88 |
end |
|
|
89 |
|
|
|
90 |
end |
|
|
91 |
|
|
|
92 |
function isValid=checkNeighbour(curPixel,nextPixel,threshold) |
|
|
93 |
isValid=1; |
|
|
94 |
if (curPixel==threshold) |
|
|
95 |
isValid=0; |
|
|
96 |
end |
|
|
97 |
if(abs(nextPixel-curPixel)>0) |
|
|
98 |
isValid=0; |
|
|
99 |
end |
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|