EI2011!12!16 Segmentation Double(1)

download EI2011!12!16 Segmentation Double(1)

of 22

Transcript of EI2011!12!16 Segmentation Double(1)

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    1/22

    Image segmentation

    Stefano Ferrari

    Universita degli Studi di [email protected]

    Elaborazione delle immagini

    (Image processing I)

    academic year 20112012

    Segmentation by thresholding

    Thresholding is the simplest segmentation method.

    The pixels are partitioned depending on their intensity value.

    Global thresholding, using an appropriate threshold T:

    g(x, y) =

    1, if f(x, y) > T0, if f(x, y) T

    Variable thresholding, if T can change over the image. Local or regional thresholding, if T depends on a

    neighborhood of (x, y). adaptive thresholding, if T is a function of (x, y).

    Multiple thresholding:

    g(x, y) =

    a, if f(x, y) > T2b, if T1 < f(x, y) T2c, if f(x, y) T1

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 1

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    2/22

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    3/22

    Illumination and reflection role in thresholding

    A B A B

    Global thresholding

    A simple algorithm:

    1. Initial estimate of T

    2. Segmentation using T: G1, pixels brighter than T; G2, pixels darker than (or equal to) T.

    3. Computation of the average intensities m1 and m2 of G1 and

    G2.

    4. New threshold value:

    Tnew =m1 + m2

    2

    5. If |T Tnew| > T, back to step 2, otherwise stop.

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 3

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    4/22

    Global thresholding: an example

    Otsus method

    Otsus method is aimed in finding the optimal value for theglobal threshold.

    It is based on the interclass variance maximization. Well thresholded classes have well discriminated intensity

    values. M N image histogram:

    L intensity levels, [0, . . . , L 1];

    ni #pixels of intensity i:

    MN =L1i=0

    ni

    Normalized histogram:

    pi =ni

    MN

    L1

    i=0

    pi = 1, pi 0

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 4

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    5/22

    Otsus method (2)

    Using k, 0 < k < L 1, as threshold, T = k: two classes: C1 (pixels in [0, k]) and C2 (pixels in

    [k + 1, L 1]) P1 = P(C1) =

    ki=0 pi, probability of the class C1

    P2 = P(C2) =PL1

    i=k+1 pi = 1 P1, probability of the class C2

    m1, mean intensity of the pixels in C1:

    m1 =

    ki=0

    i P(i|C1)

    =

    ki=0

    iP

    (C1|i)

    P(

    i)P(C1)

    =1

    P1

    ki=0

    i pi

    where P(C1|i) = 1, P(i) = pi e P(C1) = P1.

    Otsus method (3)

    Similarly, m2, mean intensity of the pixels in C2:

    m2 =1

    P2

    L1i=k+1

    i pi

    Mean global intensity, mG:

    mG =

    L1i=0

    i pi

    while the mean intensity up to the k level, m:

    m =k

    i=0

    i pi

    Hence:

    P1m1 + P2m2 = mG

    P1 + P2 = 1

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 5

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    6/22

    Otsus method (4)

    The global variance 2G:

    2G =

    L1i=0

    (i mG)2 pi

    The between-class variance, B, can be defined as:

    2B = P1(m1 mG)

    2 + P2(m2 mG)2

    = P1P2(m1 m2)2

    =

    (mGP1 m)2

    P1(1 P1) x

    The goodness of the choice T = k can be estimated as theratio :

    =2B

    2G

    Otsus method (5)

    The quantities required for the computation of , can beobtained from the histogram:

    Hence, for each value of k, (k) can be computed:

    (k) =2B(k)

    2G

    where

    2B(k) =

    (mGP1(k) m(k))2

    P1(k) (1 P1(k))

    The optimal threshold value, k, satisfies:

    2B(k

    ) = max0

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    7/22

    Otsus method: an example

    a bc d

    (a) original image;

    (b) histogram of(a);

    (c) globalthreshold:T = 169,

    = 0.467;(d) Otsus method:

    T = 181, = 0.944.

    Smoothing

    Otsus method may not work in presence of noise.

    Smoothing can produce a histogram with separated peaks.

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 7

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    8/22

    Significance of the histogram

    If the distribution is not balanced, no information can beextracted from the histogram.

    Smoothing cannot help.

    Selection of the border region

    Edge extraction techniques (e.g., Laplacian), can be used forselecting the region that carry the valuable information: Those pixels that belong to the objects and to the background

    with an equal probability.

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 8

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    9/22

    Use of edge for global thresholding (2)

    Changing the threshold of the Laplacian, severalsegmentations are obtained. It can be useful for nested classes.

    Multiple thresholds Otsus method

    The Otsus method can be applied also for the multiplethresholds segmentation (generally, double threshold).

    Between-class variance:

    2B(k1, k2) = P1(m1mG)

    2 + P2(m2mG)2 + P3(m3mG)

    2

    The optimal thresholds k1 and k

    2 can be computed as:

    2B(k

    1 , k

    2 ) = max0

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    10/22

    Multiple thresholds Otsus method: an example

    Image partitioning based thresholding

    In order to face non uniform illumination or reflectance, theimage is partitioned and the thresholding is operated on eachpartition. In each partition, the illuminance and reflectance is supposed

    uniform. In each partition, objects and background have to be equally

    represented.

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 10

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    11/22

    Local properties based thresholding

    Local properties (e.g., statistics) based criteria can be used foradapting the threshold.

    For example: Txy = axy + bmxy Txy = axy + bmG

    The segmentation is operated using a suitable predicate, Qxy:

    g(x, y) =

    1, if Qxy0, otherwise

    where Qxy can be, for instance: f(x, y) > Txy f(x, y) > axy AND f(x, y) > bmxy

    This technique can be easily generalized to multiple thresholdssegmentation.

    Local properties based thresholding: an example

    a bc d

    (b) segmentation of (a)

    with double thresholdOtsu;

    (c) local (33) standarddeviation;

    (d) segmentation withlocal thresholding.

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 11

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    12/22

    Moving averages thresholding

    Pixels are visited following a zigzag path and the statistics are

    computed using only the last n visited pixels.

    Growing based segmentation

    Region growing is a technique based on a controlled growingof some initial pixels (seeds).

    The selection of the seeds can be operated manually or usingautomatic procedures based on appropriate criteria. A-priori knowledge can be included. It is strictly application-dependent.

    The growing is controlled by the connectivity. The stop rule is another parameter of the algorithm.

    It can depend on the a-priori knowledge on the problem.

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 12

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    13/22

    Region growing: the basic algorithm

    Given: f(x, y), the image to be segmented;

    S(x, y), binary image with the seeds (it is 1 only wherethe seeds are located);

    Q, predicate to be tested for each location (x, y).

    A simple region growing algorithm (based on 8-connectivity) is thefollowing:

    1. Erode all the connected components of S until they are onlyone pixel wide.

    2. Generate the binary image fQ such that fQ(x, y) = 1 ifQ(x, y) is true.

    3. Create the binary image g where g(x, y) = 1 if fQ(x, y) = 1and (x, y) is 8-connected to a seed in S.

    4. The resulting connected components in g are the segmentedregions.

    Region growing: an example

    a b cd e fg h i

    (a) f

    (c) S(x, y) :=

    f(x, y) > 254

    (d) erosion of S

    (e) |f S|

    (h) |f S| > 68

    (i) segmentation byregion growingwithQ := |fS|

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    14/22

    Region splitting and merging

    Iterative subdivision of the image in homogeneous regions(splitting).

    Joining of the adjacent homogeneous regions (merging).

    Given an image f and a predicate Q, the basic algorithm is:

    1. R1 = f

    2. Subdivision in quadrants of each region Ri for whichQ(Ri) = FALSE.

    3. If Q(Ri) = TRUE for every regions, merge those adjacentregions Ri and Rj such that Q(Ri Rj) = TRUE; otherwise,repeat step 2.

    4. Repeat the step 3 until no merging is possible.

    Quadtree based partitioning

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 14

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    15/22

    Splitting and merging: an example

    a bc d

    Q := > a AND

    0 < m < b

    (b) 32 32

    (c) 16 16

    (b) 8 8

    Watershed

    The watershed technique is based on atopological interpretation of the image. The intensity levels represent the height

    of the terrain that describe mountainsand basins.

    For each basin, a hole in its minimum issupposed to be realized, from which, the

    rising underground water spills and fillsthe basins.

    As the water rises, the level reach theborder of the basin and two or moreadjacent basins tend to merge together.

    Dams are required for maintaining aseparation between basins.

    These dams are the borders of theregions of the segmentation.

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 15

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    16/22

    Watershed (2)

    Watershed (3)

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 16

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    17/22

    Dams construction

    The dams can bebuild usingmorphologicaldilation.

    Starting from the laststep before merging,dilation can beperformed until thetwo disjointcomponents becomeconnected.

    Dams construction (2)

    The dams can be realized setting the pixels at L (where thelevels of intensity are in [0, L 1]).

    Generally, the watershed algorithm is applied to the gradientof the image to be segmented.

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 17

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    18/22

    Watershed: an example

    Watershed with marker

    Noise as well as irrelevant details make difficult theapplication of the watershed technique in real images. Oversegmentation can be produced.

    These problems can be handled limiting the flooding throughmarkers: internal, associated to the object of interest; external, associated to the background (border of the objects).

    The watershed algorithm can then be applied considering themarker as the only minimum points from which starting theprocedure.

    The criteria used for defining the markers incorporate thea-priori knowledge on the problem.

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 18

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    19/22

    Watershed with markers: an example

    Oversegmentation obtained applying watershed to the imagegradient.

    Watershed with markers: an example (2)

    a b

    (a) Smoothing of the original image.

    Internal markers are defined as minimum points that formsconnected components (in red).

    The application of the watershed starting from internalmarkers generates the dams (in green), that can be used asexternal markers.

    (b) Segmentation obtained applying watershed in each region of (a).

    Other segmentation algorithms can be applied to the single

    regions, as well.

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 19

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    20/22

    Texture based segmentation

    a bc d

    (a) 600600 pixelsimage

    (b) Closing of (a)using a disk of 30pixels of radius.

    (c) Opening using adisk of 60 pixels ofradius.

    (d) Segmentationboundary obtainedas morphologicalgradient.

    Color based segmentation

    HSI space

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 20

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    21/22

    Color based segmentation (2)

    a bc d

    (a) Binarysaturationmask(threshold at90%);

    (b) product of themask by thehue;

    (d) segmentation

    of (b) based onits histogram(c).

    Color based segmentation (3)

    RGB space: selection of colors similar to a Criterion: D(z, a) < D0

    D(z, a) = ||z a|| =

    (z a)T(z a) 1

    2

    D(z, a) =

    (z a)TC1(z a) 1

    2

    .

    Stefano Ferrari Elaborazione di immagini (Image processing) a.a. 2011/12 21

  • 7/27/2019 EI2011!12!16 Segmentation Double(1)

    22/22

    Color based segmentation (4)

    ab

    (a) Manual selection of the color ofinterest. Average color computation,

    a = [aR aG aB] Standard deviation of the

    color of the selected pixelscomputation, = [R G B].

    (b) Segmentation of the pixels thathave a red channel value in theinterval [aR R, aR + R].

    .