![Page 1: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/1.jpg)
Image Segmentation and Image Segmentation and Edge DetectionEdge Detection
Digital Image ProcessingInstructor: Dr. Cheng-Chien Liu
Department of Earth Sciences
National Cheng Kung University
Last updated: 21 October 2003
Chapter 7Chapter 7
![Page 2: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/2.jpg)
IntroductionIntroduction
Image Segmentation and Edge DetectionImage Segmentation and Edge Detection• Purpose extract information (outlines) division
(color, brightness) automatic vision system• The simplest method of division
Histogramming and thresholding One thresholdlabel (classified) imagee.g. Fig 7.1
• Hysteresis thresholding Two thresholdse.g. Fig 7.2Principle minimize the number of misclassified pixelsp-tile method
![Page 3: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/3.jpg)
The minimum error threshold The minimum error threshold methodmethod
Total error (Fig 7.3)Total error (Fig 7.3)• E(t) = -
t p0(x)dx + (1 – t pb(x)dx
: the fraction of the pixels that make up the object1-: the fraction of the pixels that make up the background
• E/t = p0(t) – (1 – pb(t)Example 7.1: E(t) E/tB7.1: the Leibnitz ruleExample 7.2: draw p0(x) and pb(x)
Example 7.3: given p0(x), pb(x) and t
Example 7.4: given p0(x), pb(x) and t E(t)
![Page 4: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/4.jpg)
The minimum error threshold The minimum error threshold method (cont.)method (cont.)
DrawbacksDrawbacks• Need the prior knowledge of p0(x), pb(x) and
Approximate p0(x) and pb(x) by normal distributions still need to estimate the parameters and
Two solutions of t t1 < x < t2 (Example 7.6)
Example 7.5: the result of optimal thresholding is worse than that obtained by hysteresis thresholding with two heuristically chosen thresholds (Fig 7.4d)
![Page 5: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/5.jpg)
Otsu’s threshold methodOtsu’s threshold method
DerivationDerivation• Fraction
Background pixels: (t)Object pixels: 1 – (t)
• Mean gray valueThe whole image: Background: b
Object: o
• VarianceThe whole image: T
2
Background: b2
Object: o2
![Page 6: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/6.jpg)
Otsu’s threshold method (cont.)Otsu’s threshold method (cont.)
Derivation (cont.)Derivation (cont.)• T
2 = W2 + B
2 The within-class variance:
W2 = (t)b
2 + (1 – (t))o
2
he between-class variance: B
2 = (b – )2(t) + (o – )2(1 – (t))
• Otsu’s thresholding:Optimizing t to maximize B and minimize W
If work with B (Example 7.7) B(t) – (t)(t)(t)
![Page 7: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/7.jpg)
Otsu’s threshold method (cont.)Otsu’s threshold method (cont.)
DrawbacksDrawbacks• Assume and are sufficient in representing
p0(x) and pb(x)
• Break down when p0(x) and pb(x) are very unequal
• Assume the histogram of the image is bimodal
• Dividing the image into two classes is not valid under variable illumination
![Page 8: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/8.jpg)
Variable illuminationVariable illumination
ppzz((uu) = ) = pprr((uu – – ii))ppii((ii))ddii
• f(x, y) = r(x, y) i(x, y)An image f(x, y) is a product of a reflectance function r(x, y) and an
illumination function i(x, y)
• ln f(x, y) = ln r(x, y) + ln i(x, y)Multiplicative additive
• f(x, y) = r(x, y) + i(x, y)• z = Pz(u) = probability of z u P(z u)
= r
u-i pri(r, i)drdi• pz(u) = dPz(u)/du =
pri(u-i, i)di = pr(u – i)pi(i)di
• If i = const i = const pi(i) = (i – io) pz(u) = pr(u)• If i const the thresholding methods break down
![Page 9: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/9.jpg)
Variable illumination (cont.)Variable illumination (cont.)
Solution for non-uniform illuminationSolution for non-uniform illumination• Divide the image into (more or less) uniformly
illuminated patches (Fig 7.8)
• Correcting the effect of illuminationPure illumination field i(x, y)Image of an uniform reflectance surface f(x, y)f(x, y) / i(x, y) Subtract i(x, y) from z(x, y)Multiply f(x, y) / i(x, y) with a reference value, say i(0, 0) to
bring the whole image under the same illumination
![Page 10: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/10.jpg)
Shortcomings of the thresholding Shortcomings of the thresholding methodsmethods
The spatial proximity of the pixels in the The spatial proximity of the pixels in the image is not considered at allimage is not considered at all• Fig 7.8• Fig 7.9
SolutionsSolutions• Region growing method
Seed pixels attach neighboring pixels based on the predefined range scan and assign all pixels to a region
• Split and merge methodTest the original image split into four quadrants if LV < attribute <
HV test for each quadrant split … merge the region with the same attribute (Fig 7.10)
Favored when the image is square with N = 2n
![Page 11: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/11.jpg)
Pattern recognitionPattern recognition
Texture regionTexture region• Regions are not uniform in terms of their grey values
but are perceived as uniform
For segmentation purposesFor segmentation purposes• Characterize a pixel
Its GL and the variation of GL in a small patch around itNot just a scalar (GL), but a vector (feature)
Pattern recognitionPattern recognition• Multidimensional histograms clustering• Beyond the scope of this book
![Page 12: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/12.jpg)
Edge detectionEdge detection
MeasurementMeasurement• Convolve the image with a window
Slide a window calculate the statistical properties compare the difference specify the boundary
e.g. 8 8 image in Fig 7.11
• The smallest window two pixels the first derivativefx = f(i+1, j) - f(i, j)fy = f(i, j+1) - f(i, j)The dual grid
• Non-maxima suppressionThe process of identifying the local maxima as candidate edge pixels
(edgels)If there is no noise in the image pick up the discontinuities in intensity
![Page 13: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/13.jpg)
Edge detection (cont.)Edge detection (cont.)
NoiseNoise• Smooth the image with a lowpass filter before
detecting the edges (Fig 7.12, 7.13)
1D case1D case• Ai (Ii-1 + Ii + Ii+1) / 3• Fi (Ai+1 – Ai) + (Ai – Ai-1) / 2• Fi (Ii+2 + Ii+1 – Ii-1 – Ii-2) / 6• The larger the mask used, the better is the
smoothing, the more blurred and more inaccurate its position will be (Fig 7.14)
![Page 14: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/14.jpg)
Edge detection (cont.)Edge detection (cont.)
2D case (3 2D case (3 3 mask) 3 mask)• Consider fy only (rotating 900 to calculate fx)
• Symmetry: left right
• Local difference = front – behind
• Zero response for a smooth image aij = 0
• Differentiate in the direction of columns for a smooth image 0 for each column a21 = 0
aa1111 aa1212 aa1313
aa1111 aa1212 aa1111
aa1111 aa1212 aa1111
aa1111 aa1212 aa1111
aa1111 aa1212 aa1111
aa2121 aa2222 aa2323 aa2121 aa2222 aa2121 aa2121 aa2222 aa2121 aa2121 --22aa2121 aa2121 00 00 00
aa3131 aa3232 aa3333 aa3131 aa3232 aa3131 -a-a1111 -a-a1212 -a-a1111 -a-a1111 -a-a1212 -a-a1111 -a-a1111 -a-a1212 -a-a1111
![Page 15: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/15.jpg)
Edge detection (cont.)Edge detection (cont.)
2D case (cont.2D case (cont.))• Divide by a11 one parameter mask
11 KK 11
00 00 00
--11 -K-K --11
![Page 16: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/16.jpg)
Sobel maskSobel mask
Sobel maskSobel mask• Differentiating an image along two directions
Choose K = 2B7.2
Strength: E(i, j) = [fx2 + fy2]1/2
Orientation: a(i, j) = tan-1[fy/fx] Specify K keep E and a to response the true values of the non-discretized image
• Example 7.9:Expression of Sobel mask at (i, j)
• Example 7.10:Constructing a 99 matrix to calculate the i-gradient of a 33 matrix
• Example 7.11:Implementation of Example 7.10
![Page 17: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/17.jpg)
![Page 18: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/18.jpg)
![Page 19: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/19.jpg)
![Page 20: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/20.jpg)
![Page 21: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/21.jpg)
![Page 22: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/22.jpg)
![Page 23: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/23.jpg)
![Page 24: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/24.jpg)
![Page 25: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/25.jpg)
![Page 26: Image Segmentation and Edge Detection Digital Image Processing Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng](https://reader035.vdocuments.us/reader035/viewer/2022062721/56649f1d5503460f94c34cd6/html5/thumbnails/26.jpg)