Submitted to
Dr. Hammad Omer
Submitted By
Yumna Bilal
SP18-PEE-001
Abstract
Brain image segmentation is one of important contents of medical image processing, especially
accurate segmentation can benefit clinicians and patients, which has important meaning for clinical
diagnostics. Most of research in medical image segmentation uses magnetic resonance imaging
(MRI) images because of high contrast.
This piece of work aims at segmentation of MR images of brain to separate the three prime
component of brain i.e. white matter, gray matter and cerebrospinal fluid(csf).
1 Introduction
Medical Image Segmentation has become an important diagnostic tool in the practice of modern
medicine. Segmentation of MRI Brain images is the delineation of neuroanatomical structures as
well as brain abnormalities [1]. The study of many brain disorders involves the accurate
segmentation of Magnetic Resonance (MR) images of the brain. Such studies typically involve
large amount of data and manual tracing by a human expert which is time-consuming. In addition,
human experts show significant intra- and inter-observer variability, which complicates the
analysis of the resulting image segmentations. Hence, there is a need for automated methods that
produce fast, reliable and reproducible segmentations.
2 Literature Review
2.1 Segmentation
Segmentation is the partitioning of an image into regions that are homogeneous with respect to
some characteristics [2]. In medical context, Segmentation is the delineation of anatomical
structures and other regions of interest, i.e. lesions, tumors from images obtained using modalities
such as computed tomography (CT), X-ray, magnetic resonance imaging (MRI), positron emission
tomography (PET), single photon emission computed tomography (SPECT) or ultrasound, with a
primary goal of providing accurate representations of key anatomical structures, to be used for:
If the domain of an image is , then the segmentation problem is to determine sets (classes) Zk,
whose union represent the entire domain
N
Zk
k 1
Zk Z j ; k j
2
level of user interactivity, computer-aided semiautomatic methods, and completely automatic
methods.
In pixel-based segmentation individual pixels are assigned to different objects. Some pixel-based
methods only take the current pixel value into account, while other methods also include the
influence of pixels in a neighborhood. pixel-based segmentation methods can be more susceptible
to intensity inhomogeneities because they often are based only on the intensity values and not on
other information like gradient.
Region growing aims at finding regions that share some common characteristic feature. First a
seed point is selected. The neighboring voxels are then compared to the seed voxel and added to
the region if they fulfill some criteria of similarity. The neighboring voxels to this region are then
investigated and compared until the growing stops. The stopping criteria could for example be
relative intensity value to the seed point or gradient value. The choice of seed points and criteria
of similarity affect the final outcome of a region growing algorithm.
3
Figure 2: Broader Classification of Segmentation Methods
4
Therefore, the K-means algorithm is an iterative clustering algorithm that finds a correct
classification result which minimizes the sum squared error [5]. The K-means algorithm is
described as follows:
(1) Initialize cluster centroids 𝐶𝑖 with k random samples;
(2) Assign each sample point 𝑥𝑗 to the nearest cluster center.
1
(3) Recalculating each clustering center: 𝐶𝑖 = ∑𝑥 ∈ 𝑥𝑖 𝑥, where 𝑖 = 1,2,3, … … 𝑘
𝑁𝑖
(4) Repeat steps (2) and (3) until 𝐶𝑖 no longer changes.
5
4 Block Diagram
All these blocks have been implemented in MATLAB and code is attached at the end as
Appendix.
5 Results
5.1 Input Image
Test images have been taken from BrainWeb [6]. Segmentation of T1 weighted axial slice of brain
has been shown. The test image shown in the results contains only normal tissues (CSF, white
matter and gray matter), however tumor containing images can also be segmented successfully
just by increasing the number of clusters.
6
5.3 Skull Stripping
Afterward the noise free image is given to skull stripping process for removal of non-brain areas.
That strips the skull be thresholding, hole filling and then eroding the image.
7
5.5 Intensity Slicing and Masking
The mask outputted by K-means algorithm is used to separate each of the segment in the image
through intensity slicing and masking.
The detailed results of separation and area calculations for each tissue have been shown in Figure
8,9 and 10.
8
Figure 8: Separation of CSF from Brain
9
References
[1] Swathi, K., and Kishore Balasubramanian. "Preliminary investigations on automatic
segmentation methods for detection and volume calculation of brain tumor from MR
images." Biomedical Research 27.2 (2016).
[3] Clarke, L. P., et al. "MRI segmentation: methods and applications." Magnetic resonance
imaging 13.3 (1995): 343-368
[4] Despotović, Ivana, Bart Goossens, and Wilfried Philips. "MRI segmentation of the
human brain: challenges, methods, and applications." Computational and mathematical
methods in medicine 2015 (2015).
[5] Liu, Jianwei, and Lei Guo. "An improved K-means algorithm for brain MRI image
segmentation." 3rd International Conference on Mechatronics, Robotics and Automation,
Shenzhen, China. 2015.
10
Appendix
MATLAB Codes
Main File
close all; clear all; clc;
ipim=imread('3.jpg');
%%
%% NOISE REMOVAL
figure(6);
subplot(1,2,1);imshow(ipim), title('Input Image');
N = 3;
im = ipim;
out1 = medfilt2(im, [N N]);
subplot(1,2,2); imshow(out1,[]), title('Filtered Image');
%% Skull Stripping
im = out1;
% Seal off the bottom of the head - make the last row white.
binaryImage(end,:) = true;
% Fill the image
binaryImage = imfill(binaryImage, 'holes');
11
% Erode away 15 layers of pixels.
se = strel('disk', 15, 0);
binaryImage = imerode(binaryImage, se);
%%
figure(1);
ima = finalImage;
%% Application of K Means Segmentation
figure(2);
region = 'CSF';
mask1 = mask0;
for i= 1:m
for j = 1:n
if (abs(mask0(i,j)- 0.33) < 0.1)
mask1 (i,j) = 1;
else
mask1(i,j) = 0;
end
end
end
csf = mask1.*im2;
n_csf = (~mask1).*im2;
[np_csf, a_csf] = ROI_stats(mask1);
subplot(1,3,1),imshow(ipim); title('Input Image');
subplot(1,3,2),imshow(csf, []); title({['Region of Interest for ', region],
['No. Of Pixels = ',num2str(np_csf)], ['Normalized Area = ',num2str(a_csf)]
});
subplot(1,3,3),imshow(n_csf, []); title({'Non ROI for', region});
12
figure(3);
region = 'Gray Matter';
mask2 = mask0;
for i= 1:m
for j = 1:n
if (abs(mask0(i,j)- 0.6667) < 0.1)
mask2 (i,j) = 1;
else
mask2(i,j) = 0;
end
end
end
gm = mask2.*im2;
n_gm = (~mask2).*im2;
[np_gm, a_gm] = ROI_stats(mask2);
subplot(1,3,1),imshow(ipim); title('Input Image');
subplot(1,3,2),imshow(gm, []); title({['Region of Interest for ', region],
['No. Of Pixels = ',num2str(np_gm)], ['Normalized Area = ',num2str(a_gm)] });
subplot(1,3,3),imshow(n_gm, []);title({'Non ROI for', region});
figure(4);
mask3 = mask0;
region = 'White Matter';
for i= 1:m
for j = 1:n
if (abs(mask0(i,j)- 1) < 0.1)
mask3 (i,j) = 1;
else
mask3(i,j) = 0;
end
end
end
wm = mask3.*im2;
n_wm = (~mask3.*im2);
[np_wm, a_wm] = ROI_stats(mask3);
subplot(1,3,1),imshow(ipim); title('Input Image');
subplot(1,3,2),imshow(wm, []);title({['Region of Interest for ', region],
['No. Of Pixels = ',num2str(np_wm)], ['Normalized Area = ',num2str(a_wm)] });
subplot(1,3,3),imshow(n_wm, []); title({'Non ROI for', region});
Function kmeans
function [mu,mask]=kmeans(ima,k)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% kmeans image segmentation
%
% Input:
% ima: grey color image
% k: Number of classes
13
% Output:
% mu: vector of class means
% mask: clasification image mask
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% check image
ima=double(ima);
copy=ima; % make a copy
ima=ima(:); % vectorize ima
mi=min(ima); % deal with negative
ima=ima-mi+1; % and zero values
s=length(ima);
m=max(ima)+1;
h=zeros(1,m);
hc=zeros(1,m);
for i=1:s
if(ima(i)>0) h(ima(i))=h(ima(i))+1;end;
end
ind=find(h);
hl=length(ind);
% initiate centroids
mu=(1:k)*m/(k+1);
% start process
while(true)
oldmu=mu;
% current classification
for i=1:hl
c=abs(ind(i)-mu);
cc=find(c==min(c));
hc(ind(i))=cc(1);
end
%recalculation of means
for i=1:k,
a=find(hc==i);
mu(i)=sum(a.*h(a))/sum(h(a));
end
if(mu==oldmu) break;end;
end
14
% calculate mask
s=size(copy);
mask=zeros(s);
for i=1:s(1),
for j=1:s(2),
c=abs(copy(i,j)-mu);
a=find(c==min(c));
mask(i,j)=a(1);
end
end
Function area_ROI
function [number_pixel, area] = area_ROI(im_bin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% To Calculate the area of ROI
%
% Input:
% im_bin: binary image
% Output:
% number_pixel: number of pixels in ROI
% area: area of ROI
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%area calculation
[h,v]=size(im_bin);
area=(1/h)*(1/v)*(sum(sum(im_bin)));
number_pixel=(sum(sum(im_bin)));
15