Segmentation INF 5300 Segmentation by thresholding Anne Solberg (

advertisement
INF 5300
Segmentation by thresholding
Anne Solberg (anne@ifi.uio.no)
Methods for global thresholding
Adaptive thresholding
F1 21.3.06
INF 5300
1
Segmentation
• Segmentation of one of the most important
components of a complete image analysis system.
• Segmentation creates regions and objects in images.
• Segmentation methods can be divided into similaryand discontinuity-based methods.
• Region-based segmentation is based on similarity.
• Thresholding is based on splitting the image
histogram. Pixels belonging to the same histogram
class gets the same label. These pixels are not
necessarily neighbors.
• Edge-based segmentation is based on edge-pixels (or
line-pixels, corners etc.), which are linked together in
chains to form borders.
F1 21.3.06
INF 5300
2
Introduction to thresholding
• Automatic thresholding is important in applications
where speed or the physical conditions prevent
human interpretation.
• In bi-level thresholding, the histogram of the image is
usually assumed to have one valley between two
peaks, the peaks represent objects and background.
• Thresholding is usually a pre-process for various
pattern recognition techniques.
• Thresholding may also be a pre-process for adaptive
filtering, compression etc.
F1 21.3.06
INF 5300
3
Parametric cs. non-parametric
• Parametric techniques:
– Estimate parameters of two distributions from a given
histogram.
– Difficult or impossible to establish a reliable model.
• Non-parametric case:
– Separate the two gray level classes in an optimum manner
according to a criterion:
•
•
•
•
between-class variance
divergence
entropy
conservation of moments
– Non-parametric methods are more robust, and usually
faster.
F1 21.3.06
INF 5300
4
Automatic vs. interactive
• Automatic means that the user does not have to
specify any parameters.
• There are no truly automatic methods, always built-in
parameters (but they can be estimated
automatically).
• Distinction between automatic and interactive
methods.
• Distintion between supervised (with training) and
unsupervised (clustering).
F1 21.3.06
INF 5300
5
Global and non-contextual?
• Global methods use a single threshold for the entire
image.
• Local methods optimize new thresholds for a number
of sub-images or blocks.
• Global methods put severe restrictions on:
– the gray level characteristics of objects and background
– the uniformity in lighting and detection
• Non-contextual methods rely on the gray-level
histogram of the image.
• Contextual methods make use of the geometrical
relations between pixels.
F1 21.3.06
INF 5300
6
Basic thresholding
• If we know that the objects are brighter than the background,
we can find them by setting a threshold t such that
⎧0 if f ( x, y ) ≤ t
g ( x, y ) = ⎨
⎩1 if f ( x, y ) > t
• If we have different objects with different gray level, we can
divide the image into M grey level intervals using M-1 different
thresholds.
• Thresholding is a special case of classification (the M-level case
can be difficult to handle with thresholding).
F1 21.3.06
INF 5300
7
The role of bimodality
• To find similar objects on a
background, thresholding
methods are often based on
bimodality of the histogram.
• Assume that the objects cover a
fraction of p% of the scene.
• If objects and background are
equally probable, the resulting
image will often have a bimodal
histogram (two peaks).
• If p is very different from 50%,
the histogram will not be
bimodal.
F1 21.3.06
INF 5300
Bimodal OK fraction
Bimodal small fraction
Unimodal
8
Bi-level thresholding
• Histogram is assumed to have two peaks. Let P1 and P2 be the a priori
probabilities for background and foreground. Two distributions given
by b(z) and f(z). The complete histogram is given by:
• The probabilities of misclassifying a pixel given a threshold t:
• The total error is:
• Differentiate with respect to the threshold t:
F1 21.3.06
INF 5300
9
Bi-level thresholding
Two thresholds might be necessary
F1 21.3.06
INF 5300
10
The method of Ridler and Calvard
• Initial threshold value t0 equal to average gray level.
• Threshold value for iteration k+1 given by
• µ1(tk) is the mean value of the gray levels below the threshold
tk, and µ2(tk) the mean above the threshold.
• Note that µ1(tk) and µ2(tk) are the a posteriori mean values,
estimated from overlapping and truncated distributions. The a
priori µ1 and µ2 are unknown to us.
• The correctness of the estimated threshold depends on the
extent of overlap, as well on the validity of the assumption
P1≈P2.
F1 21.3.06
INF 5300
11
The method of Otsu
• Maximizes the a posteriori between-class variance σ2B(t) given
by
• The sum of the within-class variance σ2W and the between-class
variance σ2B is equal to the total variance σ20:
• Maximizing σ2B ⇔ minimizing σ2W
• The expression for σ2B(t) reduces to
• Optimal threshold T is found by a sequential search for the
maxmimum of σ2B(t) for values of t where 0<P1(t)<1.
• Pi is the normalized histogram for each class: Pi=ni/N
F1 21.3.06
INF 5300
12
The method of Reddi
•
The method of Reddi et al. is based on the same assumptions as the method of
Otsu, maximizing the between-class variance σ2B(t).
Reddi et al. show that σ2B(t) has a
unique maximum, and how this
maximum is found.
•
•
•
where µ1 and µ2 are the mean values below and above the threshold.
Exhaustive sequential search gives the same results as Otsu’s method.
Starting with a threshold t0= µ0 fast convergence is obtained equivalent to the
ad hoc technique of Ridler and Calvard.
This methods ties together Ridler and Calvard’s method and Otsu’s method.
F1 21.3.06
INF 5300
13
A ”minimum error” method
•
•
•
•
•
•
•
•
Kittler and Illingworth(1985) assume a mixture of two Gaussian distributions
(five unknown parameters).
Find T that minimizes the KL (Kullback-Leibler) distance between observed
the histogram and model distribution.
As t varies, model parameters change. Compute J(t) for all t, find minimum.
The criterion function has local minima at the boundaries of the gray scale.
An unfortunate starting value for an iterative search may cause the iteration
to terminate as a nonsensical threshold value.
If the starting threshold is obtained by Otsu’s method, convergence towards
the minimum error threshold is obtained.
The a posteriori model parameters will represent biased estimates (truncated
tails).
Correctness relies on small overlap. Cho et al. (1989) have an improvement.
F1 21.3.06
INF 5300
14
Maximum correlation thresholding
•
•
•
Brink (1989) maximized the correlation between the original gray level
image f and the thresholded image g.
The gray levels of the two classes in the thresholded image may be
prepresented by the two a posteriori average values µ1(t) and µ2(t):
The correlation coefficient has a very smooth behaviour, and starting
with the overall average graylevel value, the optimal threshold may be
found by a steepest ascent search for the value of T which maximizes
the correlation coefficient
F1 21.3.06
INF 5300
15
Entropy-based methods
•
•
•
Kapur et al. proposed a thresholding algorithm based on Shannon
entropy.
For two distributions separated by a threshold t the sum of the two
class entropies is:
Using
the sum of the two entropies may be written as
•
The discrete value T of t that maximizes ψ(t) is now the selected
threshold.
F1 21.3.06
INF 5300
16
Preservation of moments
• Observed image f is seen as a blurred version of a
thresholded image g with gray levels z1 and z2.
• Find threhold T such that if all below-threshold values
in f are replaced by z1, and all above-threshold values
are replaced by z2, the first three moments are
preserved.
• The i-th moment can be computed from the
normalized histogram p(z) by:
F1 21.3.06
INF 5300
17
• Let P1(t) and P2(t) denote a posteriori fractions of
below-threshold and above-threshold pixels in f.
• We want to preserve the moments
• Solving the four equations will give threshold T.
F1 21.3.06
INF 5300
18
Solving the equations
F1 21.3.06
INF 5300
19
Global vs. adaptive thresholding
• All the methods presented so far are originally global
methods.
• They can also be used locally in a subimage.
• Next, we study some other methods proposed for
adaptive thresholding.
F1 21.3.06
INF 5300
20
Example - oil spill detection
Otsu
F1 21.3.06
Kittler et. al
INF 5300
21
Example - oil spill detection
Kapur et al.
F1 21.3.06
INF 5300
Abutaleb
22
Adaptive thresholding methods
• From Trier and Jain, 1995:
–
–
–
–
–
–
–
–
Bernsen’s method
Chow and Kaneko’s method
Eikvil, Taxt and Moen’s method
Mardia and Hainsworth’s method
Niblack’s method
Taxt, Jain and Flynn’s method
Yanowitz and Bruckstein’s method
White and Rohrer’s method
F1 21.3.06
INF 5300
23
Adaptive thresholding
• A threshold is computed in a local window of size w
centered around a pixel.
• The window is moved and a new threshold can be
computed
– overlapping windows
– non-overlapping windows
– What is the effect of
non-overlapping windows?
• Local changes in background and foreground
contrast is handled better than in global thresholding.
F1 21.3.06
INF 5300
24
Bernsen’s method
• For each pixel (x,y)
t(x,y)=(Zlow+Zhigh)/2
Zlow is the smallest and Zhigh is the highest pixel value in the
local window of size r×r.
• Check for bimodality:
– Unimodal if C(x,y)= (Zlow-Zhigh) < l
• Parameter values: l and r
– How do we determine them?
F1 21.3.06
INF 5300
25
Example - Bernsen’s method
• Why is this method not suited for this kind of
images?
F1 21.3.06
INF 5300
26
Niblack’s method
• The threshold at pixel (x,y) is
t(x,y)=m(x,y)+k⋅s(x,y)
m(x,y) is the mean and s(x,y) the standard deviation in the
local window of size r×r.
• Parameters: contrast ratio k and window size r.
F1 21.3.06
INF 5300
27
Example Niblack
F1 21.3.06
INF 5300
28
Parker’s method
• Based on edge detection
• Calculate a new image D(x,y)= min(Z(x,y)-Z(xi,yi))
i=1...8
Z(x,y) is the intensity of the pixel (x,y)
D(x,y) is the negative of the gradient in the direction of the
brightest neighbor
• The local mean M(x,y) and standard deviation S(x,y) of D(x,y) is
computed in windows of size r×r
• M and S are smoothed and interpolated
• If M(x,y)≥m0 or S(x,y)≤s0 then unimodal region
• Else if D(x,y)<M(x,y)+k·S(x,y) then labeled print
• Else unlabeled
• Continue with region growing and pixel linking.
• The thresholded image highlights edges.
F1 21.3.06
INF 5300
29
Example Parker
F1 21.3.06
INF 5300
30
Which thresholding method is the best?
• The methods should be judged in light of the object recognition
task they are applied to (the error rate in recognizing objects
after object classification).
• Good performance:
– Object borders are clean
– Low number of false objects
– Each original object should consist of a single region of connedtec
pixels.
• The performance of the methods is dependent on the actual
values of the parameters used.
• Different applications will rank different methods as the best.
• For a particular application, the best approach might be to
model some of the prior knowledge about the application into
the thresholding model.
F1 21.3.06
INF 5300
31
Best thresholding for oil spill detection
Specially designed algorithm:
• Mean filtering (3x3) to reduce noise
• Multiplicative noise: standard deviation depends on
mean: threshold is set k dB below local mean
• Window size 100x100
• k is estimated based on wind level (k high for low
wind)
• Test for homogeneity
• Postprocessing:
– Simple filtering too fill small gaps
– Cluster the dark spot and see if it has included parts of the
surroundings (two clusters)
F1 21.3.06
INF 5300
32
Result - oil spill thresholding
Best global thresholding
F1 21.3.06
Adaptive threshold
INF 5300
33
Apropos vindusstørrelser
F1 21.3.06
INF 5300
34
Download