Segmenting an image using adaptive threshholding

584 Views Asked by At

I have done some research on the difference between segmentation using global thresh-holding and adaptive thresh-holding and here is my understanding...

Note: Assume a 16-bit grayscale image

Global thresh-holding: define a pixel value 0-65535. Scan through the image, make every value below the thresh-hold black, otherwise, make it white.

Adaptive thresh-holding: Define a thresh hold for every pixel, then determine whether to make it white or black.

My question is: for adaptive thresh-holding, how do I decide what the threshold is for every pixel?

EDIT: enter image description here

So looking at this diagram, N would be the number of pixels in the image. Theta represents the thresh-hold. I have no idea what the while loop condition is... I don't know what the stuff inside the while loop is but I understand how to compute it.

1

There are 1 best solutions below

5
On BEST ANSWER

If your'e looking for a simple adaptive thresholding, then you have 2 parameters:

  • C - criterion function - mean, median, max, min, or other
  • WS - neighborhood/window size (WS.x, WS.y) - 3X3, 5X5, etc...

Now you need to create an image of the adaptive threshold - AT. To generate AT - For the whole image you apply filtering based on your criterion. For each pixel p - AT(p) = the median/mean/etc.. of the local neighborhood:

 [(p-WS.x, p-WS.y), (p+WS.x, p+WS.y)]

if criterion is median - it is median filter (non linear) -

 AT = medfilter (IM, WS)

else if the criterion is averae - average filter (linear) using a kernel (the average kernel)

 AV = createAverageKernel (WS) 

 AT = IM * AV  ("*" is a convolution)

There may be a special filter, for any other kind of criterion

Then, you can apply the thresholding of the image IM, using AT.

 B_IM (p) = (IM (p) > AT (p)) ? 1 : 0

As for the adaptive thresholding algorithm in the question - it is a histogram based iterative algorithm to compute the threshold. However, the histogram can be applied on the whole image (global), or on a neighborhood of the pixel (local). So this algorithm can be applied either global or local. So in your case, this is the criterion function. It's just a more sophisticated function then media, mean, etc..

For the algorithm: First you initialize theta (the threshold) with uniform value - the weighted average of the histogram. While condition - you iterate until the former threshold equals the current threshold. In the loop - . Define lower value and upper value. Lower value is the weighted average of the histogram part that is lower than the current threshold value, and in similar manner the upper value. The current theta value is the average between the lower and the upper weighted average