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.

clear;close all;

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 ([email protected])
%  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)
elseif (tm~=0 && tm~=1)
    error('tm must be 0 or 1.');


if tm==0
    mIM=medfilt2(IM,[ws ws]);

Original Image After Segmentation

My modified code for testadaptivethresh.m


  • $\begingroup$ is it necessary to use adaptive thresholding? $\endgroup$
    – vini
    Mar 9, 2012 at 3:15
  • $\begingroup$ blogs.mathworks.com/steve/2006/06/02/cell-segmentation found this u could try it out $\endgroup$
    – vini
    Mar 11, 2012 at 15:21
  • $\begingroup$ Yes, I need to use adaptive thresholding only. If not, can you suggest me any other good segmentation method(other than region growing and FCM)? $\endgroup$
    – Gomathi
    Mar 12, 2012 at 15:57
  • $\begingroup$ www4.comp.polyu.edu.hk/~cslzhang/code.htm i found this u can look up the code for K. Zhang, H. Song and L. Zhang, “Active Contours Driven by Local Image Fitting Energy,” Pattern recognition, vol. 43, issue 4, pp. 1199-1206, April 2010. It worked well enough for this image $\endgroup$
    – vini
    Mar 12, 2012 at 17:32
  • $\begingroup$ Thank you so much. I got the output. I changed the parameter values and did morphological operations. Thank you everyone. $\endgroup$
    – Gomathi
    Mar 13, 2012 at 11:06

1 Answer 1


I saw the link of the paper (of SS Kumar) you referred and the link where you got the code (HIPR) are two different algorithms - even though both sounds like Adaptive Thresholding

First i would like to tell you the difference.

In the HIPR method, a general assumption is essentially 2 class level image - i.e. foreground and background. In any 2 class thresholding, one expects 2 peaks or regions within the image histogram, specifically background vs. forground, text vs. white paper. If you somehow found an optimal valley point in the histogram - you get cleanest division. Here is how the histogram may look like :
enter image description here

However, this valley point may be slightly shifting around the locally. There are good examples of lighting variations given there. Hence, this optimal valley point exists everywhere but slightly varies spatially, hence a universal threshold would fail. Hence, the valley point (threshold) is computed on every local region.

SS Kumar's paper's method and more specifically the class of images you are dealing with, is multi-class (multiple objects each with different intensity band and spread). In this cases, histograms are multi-modal, i.e. it has many peaks and valleys and presumably each peak correspond to different object, yet it may be even more complex.

The histogram might just look like this: (this is the same image as in paper). enter image description here

In this case, the above 2 class approach will simply fail because there is no one good valley. Which is why your first image you posted looks like black/white dots all around.

The meaning of Adaptive Thresholding here, implies that you need to identify the correct peak and the band of gray scale which covers most intensities of the lever and other objects are in stark contrasts which allows

What should you do?

First of, if it is compulsory to use Adaptive thresholding, find the histogram and see what intensity range and then for a threshold of left or to the right are the intensity boundaries which pixels should be discarded.

Alternatively you can use Region Growing or split and merge algorithm. Refer to this question for some information: What segmentation methods can be used for simple images?

  • $\begingroup$ Thank you so much. That was a very informative answer sir. $\endgroup$
    – Gomathi
    Mar 19, 2012 at 13:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.