Anda di halaman 1dari 15

Digital Image Processing

Segmentation of MR Images of Brain

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

Sets are connected such that

Zk Z j  ; k  j

2.2 Segmentation Methods


Segmentation methods can be divided into groups depending on different criteria. One aspect is
the level of user interactivity [2]. The groups are then manual methods, which require a high

2
level of user interactivity, computer-aided semiautomatic methods, and completely automatic
methods.

Figure 1: Classification of Segmentation Methods w.r.t User Interactivity

Segmentation methods can also be thought of as being region-based or pixel/voxel-based[3].


Region-based methods find connected regions. A region may have some common property like
intensity or texture, or have well defined boundaries, or a characteristic shape.

2.2.1 Pixel Based

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.

2.2.2 Region Growing

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

3 Clustering , the Chosen Method


Clustering is a process for classifying patterns in such a way that the samples within a class Zk
are more similar to one another than samples belonging to the other classes Zm, m ≠k; m = 1…K
Following are the commonly used clustering algorithms[4]
• K-mean
• Fuzzy C-mean
• Expectation Maximization
3.1 k-means Algorithm
The k-means algorithm attempts to classify a sample set 𝑋(𝑥1 , 𝑥2 , 𝑥3 , … . 𝑥𝑛 ) based on attributes
(e.g. intensity) into k clusters k < n. where n is the number of samples and 𝐶𝑖 represents the
clustering center,
1
𝐶𝑖 = 𝑁 ∑𝑥 ∈ 𝑥𝑖 𝑥
𝑖
Where 𝑖 = 1,2,3, … … 𝑘
And 𝑁 𝑖 is the number of sample of the ith cluster 𝑥𝑖 . The objective is to minimize total intra-
cluster variance in the least-square sense given by;
𝑘 𝑛
2
𝐽 = ∑ ∑‖(𝑥𝑗 − 𝐶𝑖 )‖
𝑖=1 𝑗=1
2
Where, ‖(𝑥𝑗 − 𝐶𝑖 )‖ is a distance measure between a data point 𝑥𝑗 and the cluster center 𝐶𝑖 .

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.

3.2 Flow Chart


The above algorithm can be best represented by following flow chart

Figure 3: Flow Chart of K-Means Algorithm

5
4 Block Diagram

Figure 4: Block Diagram of Implemented System

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.

5.2 Noise Removal


Input image is then subjected to noise removal process. Choice of noise removal technique
depends upon the nature of noise present in the image. In this implementation, Median filtering
has been used to remove noise.

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.

Figure 5: Step-wise Results of Skull Stripping Process

5.4 K Means Clustering


The skull stripped image is then subjected to K-Means clustering algorithms that works as
described in section 3.2 and 3.3. It takes stripped brain image and no. of desired clusters as input
and outputs a mask image that clearly delineates the desired structures and an array containing
centroid of every cluster.

Figure 6: Results of K-Means Algorithm

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.

Figure 7: Separation of Segmented Structures through Intensity Slicing

5.6 Area Calculations


At the end number of pixels and normalized area of each of the segment is calculated. The results
are shown in table 1.

CSF White Matter Gray Matter

No. of Pixels 2763 7744 9723

Normalized Area 0.06362694 0.178330454 0.22390328


Table1: Area Calculations of Segmented Image

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

Figure 9: Separation of Gray Matter from Brain

Figure 9: Separation of White Matter 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).

[2] Caesar, Jenny. "Segmentation of the brain from MR images." (2005).

[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.

[6] Brain Web, http://brainweb.bic.mni.mcgill.ca/brainweb/. Accessed 10th May, 2018.

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;

% normalize the image to 0-255 range for fast processing


max_val = max(max(im));
z = max_val/255;
im = im./z;
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(im);

% Display the original gray scale image.


figure(5); title('Image Morphology');
subplot(2, 3, 1);imshow(im,[]); title('Original Grayscale Image');

% Crop image to get rid of light box surrounding the image


% im = im(3:end-3, 4:end-4);

% Threshold to create a binary image


binaryImage = im > 20;

% Get rid of small specks of noise


binaryImage = bwareaopen(binaryImage, 10);

% Display the original gray scale image.


subplot(2, 3, 3); imshow(binaryImage,[]); title('Binary Image');

% Seal off the bottom of the head - make the last row white.
binaryImage(end,:) = true;
% Fill the image
binaryImage = imfill(binaryImage, 'holes');

subplot(2, 3, 4); imshow(binaryImage,[]); title('Cleaned Binary Image');

11
% Erode away 15 layers of pixels.
se = strel('disk', 15, 0);
binaryImage = imerode(binaryImage, se);

subplot(2, 3, 5); imshow(binaryImage, []); title('Eroded Binary Image');

% Mask the gray image


finalImage = ipim; % Initialize.
finalImage(~binaryImage) = 0;

subplot(2,3,6); imshow(finalImage, []); title('Skull Stripped Image');

%%
figure(1);
ima = finalImage;
%% Application of K Means Segmentation

k=4; %Number of clusters


[mu,mask]=kmeans(ima,k);

mask0=mat2gray(mask);% convert matrix to image

subplot(1,3,1),imshow(ipim); title('Input Image T1 Weighted Axial Slice of


Brain');
subplot(1,3,2); imshow(finalImage, []); title('Skull stripped Image');
subplot(1,3,3),imshow(mask0); title('Output of K-Mean Segmentation');
% subplot(2,2,1),imhist(mask);
im2 = im2double(ipim);
[m,n] = size(mask0);

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);

% create image histogram

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

mu=mu+mi-1; % recover real range

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

Anda mungkin juga menyukai