Image Segmentation Techniques Thresholding

Tresholding:

This technique is one of the simplest in image segmentation, it aims to change each pixel to black or white depending on its comparison with some fixed value. Usually for the picking of this value, several tecnhiques can be used:

  • Histogram Shape
  • Clustering
  • Entropy
  • Object Attributes
  • Spacial distribution
  • Local changes of a region.

Some known algorithms and their results are:

Algorithms:

Otsu’s:

After calculating a histogram, an analysis of the distribution of the gray values of an image are taken into an account. The minimun between the two peaks in a bimodal histogram is chosen as threshold. Some of its drawbacks is that generally a single threshold can’t give a good segmentation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import matplotlib
import matplotlib.pyplot as plt

from skimage.data import camera
from skimage.filters import threshold_otsu,threshold_li,threshold_adaptive

matplotlib.rcParams['font.size'] = 9


image = camera()
thresh = threshold_otsu(image)
threshli = threshold_li(image)
binary = image > thresh

#fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 2.5))
fig = plt.figure(figsize=(8, 2.5))
ax1 = plt.subplot(1, 3, 1, adjustable='box-forced')
ax2 = plt.subplot(1, 3, 2)
ax3 = plt.subplot(1, 3, 3, sharex=ax1, sharey=ax1, adjustable='box-forced')

ax1.imshow(image, cmap=plt.cm.gray)
ax1.set_title('Original')
ax1.axis('off')

ax2.hist(image)
ax2.set_title('Histogram')
ax2.axvline(thresh, color='r')

ax3.imshow(binary, cmap=plt.cm.gray)
ax3.set_title('Thresholded')
ax3.axis('off')

plt.show()

png

1
%matplotlib inline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from skimage.data import camera
def plot(thresh):
    image = camera()
    binary = image > thresh
    fig = plt.figure(figsize=(8, 2.5))
    ax1 = plt.subplot(1, 3, 1, adjustable='box-forced')
    ax2 = plt.subplot(1, 3, 2)
    ax3 = plt.subplot(1, 3, 3, sharex=ax1, sharey=ax1, adjustable='box-forced')

    ax1.imshow(image, cmap=plt.cm.gray)
    ax1.set_title('Original')
    ax1.axis('off')

    ax2.hist(image)
    ax2.set_title('Histogram')
    ax2.axvline(thresh, color='r')

    ax3.imshow(binary, cmap=plt.cm.gray)
    ax3.set_title('Thresholded')
    ax3.axis('off')

    plt.show()

Here is an example of how to put an interactive bar, for changing the threshold in a jupyter notebook.

1
2
3
4
5
6
7
from IPython.html.widgets import interact,IntSlider



interact(plot,
               thresh=IntSlider(min=0,max=300)
               )

png

1
<function __main__.plot>

Li:

Proposes to use a 2d histogram.

1
2
3
threshli = threshold_li(image)
plot(thresh)
plot(threshli)

png

png

Composite Methods

  • Huang Chau:

Ge propossed to compute first a gaussian mixture model or EM, and then look for the threshold average of means.

  • Maitra chatterje:

BActerial foraging.

  • Rogowska :

Proposed to divide an image into groups:

1
2
3
* Less 
* Equal 
* Mayor Some preprocessing might be required. 
  • Zhang :

First automatic, fast, robust and accurate segmentation for bones. Using a 3d adaptative thresholding. Basically diferencing bone and no bone images. It uses iterative 3d correlation to validate voxel clasification.

  • Vijay:

Used an adaptative filter, reducing the noises but adding some blur. Then implemented an adaptative wavelet thresholding was applied with multiscale product rule in the second step.

1
2
3
4
from skimage.data import camera
from skimage.filters import try_all_threshold
fig, ax = try_all_threshold(camera(), figsize=(50, 50), verbose=False)

png

Resources:

[1] E.A. Zanaty, Medical Image Segmentation Techniques: An Overview,Taif University, Saudi Arabia, Overview, 2016.

[2] Stéfan van der Walt, Johannes L. Schönberger, Juan Nunez-Iglesias, François Boulogne, Joshua D. Warner, Neil Yager, Emmanuelle Gouillart, Tony Yu and the scikit-image contributors. scikit-image: Image processing in Python. PeerJ 2:e453 (2014)

Ivan Felipe Rodriguez

Ivan Felipe Rodriguez
Colombian.LDS member(mormon).Mathematician. Teacher. Student at RUM: Master in Scientific Computing. Guitar. Geek xd.

Tips to take into account when using p-Values.

Some ideas from the ASA's statement on p-Values Continue reading

Tight Words.

Published on October 15, 2016