Tuesday 4 October 2016

image processing - Adaptive Thresholding for liver segmentation using Matlab


I need to segment liver from an abdominal CT image using Adaptive Thresholding. But I get the entire foreground separated from the background alone. I need only the liver part of the foreground separated. Check out the pdf file in http://www.ijcaonline.org/casct/number1/SPE34T.pdf I need an output similar to that shown in Figure 6.


I attach my coding here. Kindly help me out.


%testadaptivethresh.m
clear;close all;
im1=imread('nfliver2.jpg');
bwim1=adaptivethreshold(im1,11,0.03,0);
figure,imshow(im1);
figure,imshow(bwim1);
imwrite(bwim1,'at2.jpg');




function bw=adaptivethreshold(IM,ws,C,tm)
%ADAPTIVETHRESHOLD An adaptive thresholding algorithm that seperates the
%foreground from the background with nonuniform illumination.
% bw=adaptivethreshold(IM,ws,C) outputs a binary image bw with the local
% threshold mean-C or median-C to the image IM.
% ws is the local window size.
% tm is 0 or 1, a switch between mean and median. tm=0 mean(default); tm=1 median.
%

% Contributed by Guanglei Xiong (xgl99@mails.tsinghua.edu.cn)
% at Tsinghua University, Beijing, China.
%
% For more information, please see
% http://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htm

if (nargin<3)
error('You must provide the image IM, the window size ws, and C.');
elseif (nargin==3)
tm=0;

elseif (tm~=0 && tm~=1)
error('tm must be 0 or 1.');
end

IM=mat2gray(IM);

if tm==0
mIM=imfilter(IM,fspecial('average',ws),'replicate');
else
mIM=medfilt2(IM,[ws ws]);

end
sIM=mIM-IM-C;
bw=im2bw(sIM,0);
bw=imcomplement(bw);

Original Image After Segmentation


My modified code for testadaptivethresh.m


clear;
im=imread('nfliver7.gif');
figure,imshow(im)

bwim1=adaptivethreshold(im,300,-0.15,0);
bw=bwareaopen(bwim1,3000);
se=strel('diamond',4);
er=imerode(bw,se);
bw1=bwareaopen(er,3000);
er1=imerode(bw1,se);
bw2=bwareaopen(er1,1000);
fi=imfill(bw2,'holes');
figure,imshow(fi)


op=uint8(fi);
seg=im.*op;
figure,imshow(seg)
imwrite(seg,'sliver7.jpg');


No comments:

Post a Comment

readings - Appending 内 to a company name is read ない or うち?

For example, if I say マイクロソフト内のパートナーシップは強いです, is the 内 here read as うち or ない? Answer 「内」 in the form: 「Proper Noun + 内」 is always read 「ない...