Presentation is loading. Please wait.

Presentation is loading. Please wait.

Digital Image Processing & Pattern Analysis (CSCE 563) Image Segmentation Prof. Amr Goneid Department of Computer Science & Engineering The American University.

Similar presentations


Presentation on theme: "Digital Image Processing & Pattern Analysis (CSCE 563) Image Segmentation Prof. Amr Goneid Department of Computer Science & Engineering The American University."— Presentation transcript:

1 Digital Image Processing & Pattern Analysis (CSCE 563) Image Segmentation Prof. Amr Goneid Department of Computer Science & Engineering The American University in Cairo

2 Prof. Amr Goneid, AUC2 Image Segmentation Introduction Detection of Discontinuities Thresholding Hough Transform Motion Detection

3 Prof. Amr Goneid, AUC3 Introduction Objective: Division of image into constituent parts or objects. Prerequisite to identification or recognition. Methodologies: Detection of Discontinuities Detection of Similarities

4 Prof. Amr Goneid, AUC4 1. Detection of Discontinuities (a) Use of Masks General: R =  w i z i, |R| > T  w i = 0 (No change gives zero) Peak Point Detection: Laplacian Mask 8

5 Prof. Amr Goneid, AUC5 Example [x,map] = imread(‘stripe.bmp’); save stripe x map; load stripe; w = [-1 -1 -1; -1 8 -1; -1 -1 -1]; g = abs(imfilter(double(f), w)); subplot(1,2,1), imshow(f); subplot(1,2,1), imshow(g);

6 Prof. Amr Goneid, AUC6 Use of Masks (continued) Line Segments: 2 2 2 2 2 2 2 2 2 222 HOR VER +45º -45º

7 Prof. Amr Goneid, AUC7 Edge Detection: The Sobel Mask Horizontal Vertical s = Gxs’ = Gy 01 -202 01 -2 000 121

8 Prof. Amr Goneid, AUC8 Edge Detection Example of using Sobel Masks

9 Prof. Amr Goneid, AUC9 Edge Detection: Laplacian of Gaussian (LoG) The Laplacian is the 2 nd order derivative Seldom used alone for edge detection (sensitive to noise) A Gaussian function has a Laplacian (LoG)

10 Prof. Amr Goneid, AUC10 Edge Detection: Laplacian of Gaussian (LoG) Convolving an image with (LoG) has two effects: Smoothing (Gaussian) to reduce noise Computes the Laplacian (edge detection)

11 Prof. Amr Goneid, AUC11 Edge Detection in MATLAB For an image (f), examples of edge detection:  g = edge(f, ‘sobel’);  g = edge(f, ‘log’);  g = edge(f, ‘canny’);The best

12 Prof. Amr Goneid, AUC12 Edge Detection in MATLAB

13 Prof. Amr Goneid, AUC13 2. Thresholding (a) Using a Fixed Threshold Used with very high contrast images Objects are very bright against a dark B.G. or the reverse. A simple threshold T (e.g. 128 on a scale of 0..255)

14 Prof. Amr Goneid, AUC14 (b) Histogram-Derived Thresholding Histogram isolates image into BG & objects at threshold (T) A threshold image is obtained: G = f for f > T and Zero Otherwise P(z) z BG Objects T

15 Prof. Amr Goneid, AUC15 Example (1) Imageits Histogram

16 Prof. Amr Goneid, AUC16 Example (2) Imageits Histogram BG Triangles Circles

17 Prof. Amr Goneid, AUC17 Example (2) (continued) 0.25 0.5

18 Prof. Amr Goneid, AUC18 Histogram Smoothing A smoothing of the raw histogram data to remove small fluctuations but the smoothing algorithm must not shift the peak positions. This translates into a zero-phase smoothing (moving average) algorithm where typical values for w are 3 or 5: P smooth (z) = (1/w) ∑ i P raw (z-i) {i = -(w-1)/2.. (w-1)/2}

19 Prof. Amr Goneid, AUC19 Triangle algorithm This technique is particularly effective when one of the peaks is significantly lower than the other. A line is constructed between the maximum of the histogram at brightness z max and the lowest value z min = (p=0)% in the image. The distance d between the line and the histogram P(z) is computed for all values of z from z min to z max The threshold (T) is where the distance between P(T) and the line is maximal

20 Prof. Amr Goneid, AUC20 (c) Optimal Thresholding How to separate Dark from Bright objects using an optimal threshold ? Dark Bright Both T = ?

21 Prof. Amr Goneid, AUC21 Optimal Thresholding (continued) Assume Gaussian Probability with mean  and S.D.  so that P(z) = 1/[sqrt(2π) σ] exp{-(z-  ) 2 / (2σ2) } Dark and bright objects have such Gaussian distributions with weights W 1 and W 2 P(z) = W 1 P 1 (z) + W 2 P 2 (z)

22 Prof. Amr Goneid, AUC22 Sources of Error Assume  1 <  2 E 1 (T) =bright Classified as dark E 2 (T) =dark classified as bright E(T) = W 2 E 1 (T) + W 1 E 2 (T) T E1E1 E2E2

23 Prof. Amr Goneid, AUC23 Error Minimization E 1 (T) =  P 2 (z) dz, E 2 (T) =  P 1 (z) dz E(T) = W 2 E 1 (T) + W 1 E 2 (T) The optimal threshold is given by dE/dT=0, i.e. W 1 P 1 (T) = W 2 P 2 (T) For the Gaussian distributions, we get a quadratic equation : aT 2 + bT + c = 0 -- T T 

24 Prof. Amr Goneid, AUC24 Optimal Threshold For the Gaussian distributions, assume  1 =  2 =  so that T =½ (  1 +  2 ) + [  2 /(  1 -  2 )] ln(W 2 /W 1 )

25 Prof. Amr Goneid, AUC25 3. Detection of Lines using the Hough Transform This technique allows to discover shapes from image edges. It assumes that a primitive edge detection has already been performed on an image. It attempts to combine edges into lines, where a sequence of edge pixels in a line indicates that a real edge exists. The Hough Transform maps a straight line onto a 2-D accumulator (parameter space). Peaks in the accumulator space define lines and their parameters.

26 Prof. Amr Goneid, AUC26 Hough Transform (a) Line Representation Image Space: Image points p 1 = (x 1,y 1 ), p 2 =(x 2,y 2 ),…, p n =(x n,y n ) in x-y space. If they represent a straight line, then the points will satisfy the line form y i = a 0 x i + b 0 y x p1 p2

27 Prof. Amr Goneid, AUC27 Line Representation Parameter Space: Each point on the line generates a straight line in the parameter space a-b b = -a x + y p1 p2 pn p3 a0 a b b0

28 Prof. Amr Goneid, AUC28 Example y = 2 x + 4 Image Space(10 points) Parameter Space(10 lines) b a y x

29 Prof. Amr Goneid, AUC29 Accumulator Space The a-b parameter space can be quantized to yield a 2D accumulator. Peaks in the accumulator space give evidence of straight lines. Peak row yields b 0, and peak column yields a 0 Disadvantage: vertical lines give infinite b, a

30 Prof. Amr Goneid, AUC30 (b) Polar Representation Image Space: Same line can be represented using a polar (Normal) representation: x cos  + y sin  =  b =  / sin  a = - cot  y x  

31 Prof. Amr Goneid, AUC31 Polar Representation Parameter Space: Each point on the line generates a curve in the  -  space x cos  + y sin  =    00 00

32 Prof. Amr Goneid, AUC32 Example y = 2 x + 4 Parameter Space(10 lines)  

33 Prof. Amr Goneid, AUC33 Algorithm Initiaize ACC [ ,  ] to zero For each pixel with coordinates (x, y) For each  ( 0 to pi) compute  = x cos  + y sin  inc ( ACC [ ,  ] ) Apply Threshold and Detect Maximum Count Bin

34 Prof. Amr Goneid, AUC34 Accumulator Space Bin with maximum evidence gives ,  for the detected line: 00011000 11221100 12464210 125505210 11221100 00111000

35 Prof. Amr Goneid, AUC35 Practical Examples [ ,  ][ ,  ’] with noise

36 Prof. Amr Goneid, AUC36 Practical Examples x y   Two Lines 0 D  1 2 1 2

37 Prof. Amr Goneid, AUC37 Practical Examples Parallel Lines

38 Prof. Amr Goneid, AUC38 Practical Examples ShapeEdge DetectionAcc. Space Detected LinesSuperimposed

39 Prof. Amr Goneid, AUC39 Circle discovery using the Hough Transform If we search for circles of a known radius R, say, then the following identity can be used: (x-a) 2 + (y-b) 2 = R 2 where (a,b) is the centre of the circle. x y

40 Prof. Amr Goneid, AUC40 Circle discovery using the Hough Transform Peaks in the (a,b) space indicate the presence of circles of radius R at a certain (a 0,b 0 ). It is possible to look for the following types of circles: -Different (R): plot in (a,b,R) space. -Different (R), same vertical centres (a): plot in (b,R) space. -Different (R), same horizontal centres (b): plot in (a,R) space

41 Prof. Amr Goneid, AUC41 Other Shapes (e.g. Ellipse) Shape Detected Ellipses Superimposed

42 Prof. Amr Goneid, AUC42 4. Motion Detection (a) Spectral Methods Image frames f(x,y,t), t = 0,1,….. The x-projections are: p(x,t) =  y f(x,y,t) X0X0+1X0+t 010000001000000010 tt

43 Prof. Amr Goneid, AUC43 Motion Detection (cont.) For a pixel moving in the x-direction, a sinusoidal signal results as: g x (t) =  x p(x,t) exp{2  j k x x  t} = exp{2  j k x (x 0 + t)  t} = exp{ j  (t) } = cos  (t) + j sin  (t) k x is an arbitrary constant parameter

44 Prof. Amr Goneid, AUC44 Motion Detection (cont.) If the pixel is stationary at x 0 in the x- direction, then p(x,t) = 1 for x = x 0 and 0 otherwise so that g x (t) =  x p(x,t) exp{2  j k x x  t} = exp{2  j k x x 0  t} = constant

45 Prof. Amr Goneid, AUC45 Generally, to detect motion Form x-projections p(x,t) then the x-signal g x (t) Form y-projections q(y,t) then the y-signal g y (t) Find the 1D FFT for both: G x (u) = fft[g x (t)], G y (v) = fft[g y (t)] Significant peaks in the power spectra signal motion in the corresponding direction, with velocity u(peak)/k

46 Prof. Amr Goneid, AUC46 Example(1) Horizontal Motion 61 frames Kx = 0.2

47 Prof. Amr Goneid, AUC47 Example(2) Diagonal Motion 61 frames, Kx=Ky=0.2

48 Prof. Amr Goneid, AUC48 Example(3) Vertical Motion with Noise 61 frames, Kx=Ky=0.2

49 Prof. Amr Goneid, AUC49 (b) Randomized Hough Transform

50 Prof. Amr Goneid, AUC50 Algorithm 1.Two binary edge pictures are formed 2.Two points (bi, bj) are picked randomly from the first image. 3.A corresponding point pair (ci, cj) is sought from the second picture. 4.The transition (dx, dy) is then calculated between the points of the first and second image as 5.The cell Acc(dx, dy) is accumulated in the accumulator space. 6.repeat 2 and 3 a suitable number of repetitions

51 Prof. Amr Goneid, AUC51 Accumulator Space dx dy


Download ppt "Digital Image Processing & Pattern Analysis (CSCE 563) Image Segmentation Prof. Amr Goneid Department of Computer Science & Engineering The American University."

Similar presentations


Ads by Google