Ch10-Image Segmentation

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 22

Digital Image Processing, 2nd ed.

1
www.imageprocessingbook.com

Chapter 10
Image
Segmentation

www.ImageProcessingPlace.com
w.csie.ntnu.edu.tw/~violet/IP93/Chapter10.ppt
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. 2
www.imageprocessingbook.com

Image Segmentation

• Image segmentation divides an image into regions that


are connected and have some similarity within the region
and some difference between adjacent regions.
• The goal is usually to find individual objects in an image.
• For the most part there are fundamentally two kinds of
approaches to segmentation:
– Similarity: may be due to pixel intensity, color or texture.
– Differences: are sudden changes (discontinuities) in any of
these, but especially sudden changes in intensity along a
boundary line, which is called an edge.

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 3
www.imageprocessingbook.com

Detection of Discontinuities
• There are three kinds of discontinuities of intensity: points,
lines and edges.
• The most common way to look for discontinuities is to scan a
small mask over the image. The mask determines which kind
of discontinuity to look for.
9
R  w1 z1  w2 z 2  ...  w9 z9   wi zi
i 1

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 4
www.imageprocessingbook.com

Detection of Discontinuities
Point Detection

R T
where T : a nonnegative threshold

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 5
www.imageprocessingbook.com

Detection of Discontinuities
Point Detection
>> f = imread('point.tif');
>> imshow(f);
>> w = [-1 -1 -1; -1 8 -1; -1 -1 -1]
w=
-1 -1 -1
-1 8 -1
-1 -1 -1
>> g = abs(imfilter(double(f), w));

>> T = max(g(:))
T=
391

>> g = g >= T;
>> imshow(g);

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 6
www.imageprocessingbook.com

Detection of Discontinuities
Point Detection

>> g = abs(imfilter(double(f), w)) >= 10;


>> imshow(g);

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 7
www.imageprocessingbook.com

Detection of Discontinuities
Line Detection
• Only slightly more common than point detection is to find a
one pixel wide line in an image.
• For digital images straight lines are only horizontal, vertical,
or diagonal (+ 45 or –45).

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 8
www.imageprocessingbook.com

Detection of Discontinuities
Line Detection
>> f = imread('wirebond.tif');
>> imshow(f); % Fig 10.4(a)
>> w = [2 -1 -1; -1 2 -1; -1 -1 2];
w=
2 -1 -1
-1 2 -1
-1 -1 2
>> g = imfilter(double(f), w);
>> imshow(g, [ ]); % Fig 10.4(b)
>> gtop = g(1:120, 1:120);
>> figure, imshow(gtop, [ ]) % Fig 10.4(c)
>> gbot = g(end-119:end, end-119:end);
>> figure, imshow(gbot, [ ]) % Fig 10.4(d)
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. 9
www.imageprocessingbook.com

Detection of Discontinuities
Line Detection
>> g = abs(g);
>> figure, imshow(g, [ ]); % Fig 10.4(e)
>> T = max(g(:))
T=
1530
>> g = g >= T;
>> figure, imshow(g); % Fig 10.4(f)

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 10
www.imageprocessingbook.com

Detection of Discontinuities
Edge Detection

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 11
www.imageprocessingbook.com

Detection of Discontinuities
Edge Detection

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 12
www.imageprocessingbook.com

Detection of Discontinuities
Edge Detection

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 13
www.imageprocessingbook.com

Detection of Discontinuities
Edge Detection

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 14
www.imageprocessingbook.com

Detection of Discontinuities
Gradient Operators
• First-order derivatives:
– The gradient of an image f(x,y) at location (x,y) is defined
as the vector:
G x   f
x

f      f 
G y   y 
– The magnitude of this vector: f  mag(f )  G  G  2
x
2
y 
1
2

 Gx 
– The direction of this vector:  ( x, y )  tan  
1

 Gy 

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 15
www.imageprocessingbook.com

Detection of Discontinuities
Gradient Operators

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 16
www.imageprocessingbook.com

Detection of Discontinuities
Gradient Operators

Prewitt masks for


detecting diagonal edges

Sobel masks for


detecting diagonal edges

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 17
www.imageprocessingbook.com

Detection of Discontinuities
Edge Detection Using Matlab

Syntax: [g, t] = edge(f, ‘method’, parameters)

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 18
www.imageprocessingbook.com

Detection of Discontinuities
Edge Detection Using Matlab
>> f = imread('building.tif');
>> imshow(f); % Fig. 10.6(a)
>> [gv, t] = edge(f, 'sobel', 'vertical');
>> imshow(gv); % Fig. 10.6(b)
>> t
t=
0.0516
>> gv = edge(f, 'sobel', 0.15, 'vertical');
>> imshow(gv); % Fig. 10.6(c)
>> gboth = edge(f, 'sobel', 0.15);
>> imshow(gboth); % Fig. 10.6(d)
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. 19
www.imageprocessingbook.com

Detection of Discontinuities
Edge Detection Using Matlab

>> w45 = [-2 -1 0; -1 0 1; 0 1 2]


w45 =
-2 -1 0
-1 0 1
0 1 2
>> g45 = imfilter(double(f), w45, 'replicate');
>> T = 0.3*max(abs(g45(:)))
T=
211.8000
>> g45 = g45 >= T;
>> figure, imshow(g45); % Fig. 10.6(e)
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. 20
www.imageprocessingbook.com

Detection of Discontinuities
Edge Detection Using Matlab

>> wm45 = [0 1 2; -1 0 1; -2 -1 0]
wm45 =
0 1 2
-1 0 1
-2 -1 0
>> gm45 = imfilter(double(f), wm45, 'replicate');
>> T = 0.3*max(abs(gm45(:)))
T=
206.7000
>> gm45 = gm45 >= T;
>> figure, imshow(gm45); % Fig. 10.6(f)
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. 21
www.imageprocessingbook.com

Detection of Discontinuities
Edge Detection Using Matlab

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. 22
www.imageprocessingbook.com

References
1. Gonzalez R. C., Woods R. E., Eddins S. L., Digital Image
Processing Using Matlab, Pearson Education, 2006.
2. Gonzalez R. C., Woods R. E., Digital Image Processing,
Pearson Education, 2006.
3. http://www.imageprocessingplace.com/

© 2002 R. C. Gonzalez & R. E. Woods

You might also like