a b/Thoracic Organs Segmentation code/MAP/MaxLikelihood.m
1
function [x,y] = MaxLikelihood(Img,RibCage,Displacements);
2
3
%Maximum likelihood to belong in the inner soft tissue
4
%The features are:
5
%Pixels Intensity
6
%Displacement values towards x and y axis
7
8
9
%define the region inside the rib cage
10
Mask=imfill(RibCage);
11
Mask=imerode(Mask, strel(ones(10,10)));
12
13
%find the pixels with gray intensities inside the rib cage
14
Pixels= find(Mask==1 & Img>0);
15
16
%Find the intensity values of the non-zero pixels
17
IntensityValues=Img(Pixels);
18
19
%Find the displacements values of the gray pixels
20
DisplacementXY=Displacements([Pixels,Pixels+size(Displacements,1)*size(Displacements,2)]);
21
DisplacementXY=reshape(DisplacementXY,[ length(Pixels),2]);
22
23
24
[Pmax,ClassNum,Pixels]= NaiveBayesianClassifier(Pixels,IntensityValues, DisplacementXY);
25
%ClassNum==1 means that the pixel belongs to heart, otherwise to
26
%background.
27
28
ProbabilitiesHeartMap=zeros(size(Img));
29
ProbabilitiesHeartMap(Pixels(ClassNum==1))=Pmax(ClassNum==1);
30
ProbabilitiesHeartMap = imerode(ProbabilitiesHeartMap ,strel(ones(10,10)));
31
Pixel = find(ProbabilitiesHeartMap==max(max(ProbabilitiesHeartMap)));
32
33
x=0;y=0;
34
%coordinates of the pixel
35
[y,x] = ind2sub([size(Img,1),size(Img,2)],Pixel(1));
36
37
38