segment skull out of Mri image
11 views (last 30 days)
Show older comments
hello
can you please help me to fing what is wong with my code , i have to remove the skull out of this mri image but it not happing , i don't have clue why,
I=imread('C1 brain.jpg');
figure(1); imshow(I); title('original image');
tresholds(2,3);
p=95;
[rmax cmax]=size(I);
pxn=rmax*cmax;
T=0;
while max(size(find(I==0)))< p*pxn/100
T=T+1;
I(find(I==T))=0;
end
I(find(I>T))=1;
tresholds(1,1)=T;
tresholds(2,1)=p;
figure(2); colormap('gray');imagesc(I);
se1=strel('disk', 5);
A=imerode(I,se1);
figure(3); imshow(A); title('eroded');
B=A.*-1;
figure(4); imshow(B); title('B');
C=B-1;
figure(5); imshow(C); title('C');
se2=strel('disk', 3);
D=imdilate(C,se2)
figure(6); imshow(D); title('dilated');
F=I-D;
figure(7); imshow; title('final');
0 Comments
Answers (1)
Image Analyst
on 22 Oct 2021
There are lots of ways to do it depending on what method you want to use and how accurate you'd like it. If you want to do it by thresholding and erosion like you tried, try this:
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
grayImage=imread('C1 brain.jpg');
subplot(2, 2, 1)
imshow(grayImage);
axis('on', 'image');
impixelinfo;
title('Original Image', 'FontSize', fontSize);
lowThreshold = 20;
highThreshold = 255;
% Interactive threshold using Image Analyst's utility.
% https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle
% [lowThreshold, highThreshold] = threshold(lowThreshold, highThreshold, grayImage)
mask = grayImage >= lowThreshold & grayImage <= highThreshold;
% Don't let top of skull touch top edge of image.
mask(1, :) = false;
subplot(2, 2, 2)
imshow(mask);
title('Initial Mask Image', 'FontSize', fontSize);
% Erode the mask some
radius = 29;
se = strel('disk', radius, 0);
mask = imfill(mask, 'holes');
mask = imerode(mask, se);
% Don't erase face and neck.
mask(400:end, 1:600) = true;
subplot(2, 2, 3)
imshow(mask);
title('Final Mask Image', 'FontSize', fontSize);
% Erase gray image
grayImage(~mask) = 0;
subplot(2, 2, 4)
imshow(grayImage);
title('Final Gray Scale Image', 'FontSize', fontSize);
g = gcf;
g.WindowState = 'maximized'
I've also attached my standard skull stripping demo.
0 Comments
See Also
Categories
Find more on Medical Physics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!