0% found this document useful (0 votes)
13 views10 pages

DSP PBL

The document describes a project to detect brain tumors in MRI images using MATLAB. It performs pre-processing like filtering and thresholding on MRI images. Morphological operations are then used to detect tumor regions based on characteristics like solidity and area. Bounding boxes are drawn around detected tumors. The tumor outline is extracted and overlaid on the filtered image in green color to show the detected tumor location. The goal is to build a 3D tumor detection system by analyzing 2D images from different angles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views10 pages

DSP PBL

The document describes a project to detect brain tumors in MRI images using MATLAB. It performs pre-processing like filtering and thresholding on MRI images. Morphological operations are then used to detect tumor regions based on characteristics like solidity and area. Bounding boxes are drawn around detected tumors. The tumor outline is extracted and overlaid on the filtered image in green color to show the detected tumor location. The goal is to build a 3D tumor detection system by analyzing 2D images from different angles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Brain Tumor Detection and Segmentation from MRI

Images.
Aim: To find tumor of given MRI image by using matlab s/w

Equipment Required: Computer with pre loaded OS and Matlab 2016b software version
software with image processing tool box

ABSTRACT

Brain Tumor is a fatal disease which cannot be confidently detected without MRI. In the project,
it is tried to detect whether patient’s brain has tumor or not from MRI image using MATLAB
simulation.
To pave the way for morphological operation on MRI image, the image was first filtered using
Anisotropic Diffusion Filter to reduce contrast between consecutive pixels. After that the image
was resized and utilizing a threshold value image was converted to a black and white image
manually. This primary filters the plausible locations for tumor presence.
On this semi processed image morphological operations have been applied and information on
solidity and areas of the plausible locations was obtained. A minimum value of both of these
characters has been determined from statistical average of different MRI images containing
tumor. Then it was used to deliver final detection result.
Though this simulation routine can give correct result most of the time, it fails to perform when
tumor’s size is too small or tumor is hollow.
The larger goal of the project is to build a data base of 2D image data of tumor from the MRI
images taken from different angle of a particular human and by analyzing them to point out the
exact 3D location of the tumor . To fulfill this, 2D tumor detection and segmentation have been
developed to better accuracy so that 3D detection can be more reliable. This is the primary target
of the project.

Function:

function diff_im = anisodiff(im, num_iter, delta_t, kappa, option)


fprintf('Removing noise\n');

fprintf('Filtering Completed !!');

% Convert input image to double.


im = double(im);

% PDE (partial differential equation) initial condition.


diff_im = im;

% Center pixel distances.


dx = 1;
dy = 1;
dd = sqrt(2);

% 2D convolution masks - finite differences.


hN = [0 1 0; 0 -1 0; 0 0 0];
hS = [0 0 0; 0 -1 0; 0 1 0];
hE = [0 0 0; 0 -1 1; 0 0 0];
hW = [0 0 0; 1 -1 0; 0 0 0];
hNE = [0 0 1; 0 -1 0; 0 0 0];
hSE = [0 0 0; 0 -1 0; 0 0 1];
hSW = [0 0 0; 0 -1 0; 1 0 0];
hNW = [1 0 0; 0 -1 0; 0 0 0];

% Anisotropic diffusion.
for t = 1:num_iter

% Finite differences. [imfilter(.,.,'conv') can be replaced by


conv2(.,.,'same')]
nablaN = imfilter(diff_im,hN,'conv');
nablaS = imfilter(diff_im,hS,'conv');
nablaW = imfilter(diff_im,hW,'conv');
nablaE = imfilter(diff_im,hE,'conv');
nablaNE = imfilter(diff_im,hNE,'conv');
nablaSE = imfilter(diff_im,hSE,'conv');
nablaSW = imfilter(diff_im,hSW,'conv');
nablaNW = imfilter(diff_im,hNW,'conv');

% Diffusion function.
if option == 1
cN = exp(-(nablaN/kappa).^2);
cS = exp(-(nablaS/kappa).^2);
cW = exp(-(nablaW/kappa).^2);
cE = exp(-(nablaE/kappa).^2);
cNE = exp(-(nablaNE/kappa).^2);
cSE = exp(-(nablaSE/kappa).^2);
cSW = exp(-(nablaSW/kappa).^2);
cNW = exp(-(nablaNW/kappa).^2);
elseif option == 2
cN = 1./(1 + (nablaN/kappa).^2);
cS = 1./(1 + (nablaS/kappa).^2);
cW = 1./(1 + (nablaW/kappa).^2);
cE = 1./(1 + (nablaE/kappa).^2);
cNE = 1./(1 + (nablaNE/kappa).^2);
cSE = 1./(1 + (nablaSE/kappa).^2);
cSW = 1./(1 + (nablaSW/kappa).^2);
cNW = 1./(1 + (nablaNW/kappa).^2);
end

% Discrete PDE solution.


diff_im = diff_im + ...
delta_t*(...
(1/(dy^2))*cN.*nablaN + (1/(dy^2))*cS.*nablaS + ...
(1/(dx^2))*cW.*nablaW + (1/(dx^2))*cE.*nablaE + ...
(1/(dd^2))*cNE.*nablaNE + (1/(dd^2))*cSE.*nablaSE + ...
(1/(dd^2))*cSW.*nablaSW + (1/(dd^2))*cNW.*nablaNW );
end
Main Program:

clc
close all
clear all

%% Input
[I,path]=uigetfile('*.jpg','select a input image');
str=strcat(path,I);
s=imread(str);

figure;
imshow(s);
title('Input image','FontSize',20);

%% Filter
num_iter = 10;
delta_t = 1/7;
kappa = 15;
option = 2;
disp('Preprocessing image please wait . . .');
inp = anisodiff(s,num_iter,delta_t,kappa,option);
inp = uint8(inp);

inp=imresize(inp,[256,256]);
if size(inp,3)>1
inp=rgb2gray(inp);
end
figure;
imshow(inp);
title('Filtered image','FontSize',20);

%% thresholding
sout=imresize(inp,[256,256]);
t0=60;
th=t0+((max(inp(:))+min(inp(:)))./2);
for i=1:1:size(inp,1)
for j=1:1:size(inp,2)
if inp(i,j)>th
sout(i,j)=1;
else
sout(i,j)=0;
end
end
end

%% Morphological Operation

label=bwlabel(sout);
stats=regionprops(logical(sout),'Solidity','Area','BoundingBox');
density=[stats.Solidity];
area=[stats.Area];
high_dense_area=density>0.6;
max_area=max(area(high_dense_area));
tumor_label=find(area==max_area);
tumor=ismember(label,tumor_label);

if max_area>100
figure;
imshow(tumor)
title('tumor alone','FontSize',20);
else
h = msgbox('No Tumor!!','status');
%disp('no tumor');
return;
end

%% Bounding box

box = stats(tumor_label);
wantedBox = box.BoundingBox;
figure
imshow(inp);
title('Bounding Box','FontSize',20);
hold on;
rectangle('Position',wantedBox,'EdgeColor','y');
hold off;

%% Getting Tumor Outline - image filling, eroding, subtracting


% erosion the walls by a few pixels

dilationAmount = 5;
rad = floor(dilationAmount);
[r,c] = size(tumor);
filledImage = imfill(tumor, 'holes');

for i=1:r
for j=1:c
x1=i-rad;
x2=i+rad;
y1=j-rad;
y2=j+rad;
if x1<1
x1=1;
end
if x2>r
x2=r;
end
if y1<1
y1=1;
end
if y2>c
y2=c;
end
erodedImage(i,j) = min(min(filledImage(x1:x2,y1:y2)));
end
end
figure
imshow(erodedImage);
title('eroded image','FontSize',20);
%% subtracting eroded image from original BW image

tumorOutline=tumor;
tumorOutline(erodedImage)=0;

figure;
imshow(tumorOutline);
title('Tumor Outline','FontSize',20);

%% Inserting the outline in filtered image in green color

rgb = inp(:,:,[1 1 1]);


red = rgb(:,:,1);
red(tumorOutline)=255;
green = rgb(:,:,2);
green(tumorOutline)=0;
blue = rgb(:,:,3);
blue(tumorOutline)=0;

tumorOutlineInserted(:,:,1) = red;
tumorOutlineInserted(:,:,2) = green;
tumorOutlineInserted(:,:,3) = blue;

figure
imshow(tumorOutlineInserted);
title('Detected Tumer','FontSize',20);

%% Display Together

figure
subplot(231);imshow(s);title('Input image','FontSize',20);
subplot(232);imshow(inp);title('Filtered image','FontSize',20);

subplot(233);imshow(inp);title('Bounding Box','FontSize',20);
hold on;rectangle('Position',wantedBox,'EdgeColor','y');hold off;

subplot(234);imshow(tumor);title('tumor alone','FontSize',20);
subplot(235);imshow(tumorOutline);title('Tumor Outline','FontSize',20);
subplot(236);imshow(tumorOutlineInserted);title('Detected
Tumor','FontSize',20);

Data base:
Results: Hence, I observed Brain Tumor Detection and Segmentation from MRI
Images by using matlab software.

You might also like