Вы находитесь на странице: 1из 4

Distance measures

• Given pixels p, q, and z at (x,y), (s,t) and (u,v) respectively,


• D is a distance function (or metric) if:
– D(p,q) ≥ 0 (D(p,q)=0 iff p=q),
Computer Vision & – D(p,q) = D(q,p), and
Digital Image Processing – D(p,z) ≤ D(p,q) + D(q,z).
• The Euclidean distance between p and q is given by:

Basic Image Processing Operations De ( p, q ) = ( x − s ) 2 + ( y − t ) 2


• The pixels having distance less than or equal to some value
r from (x,y) are the points contained in a disk of radius r
centered at (x,y)

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-1 Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-2

Distance measures (continued) Distance measures (continued)

• The D4 distance (also called the city block distance) • The D8 distance (also called the chessboard distance)
between p and q is given by: between p and q is given by:

D4 ( p, q ) = x − s + y − t D8 ( p, q ) = max( x − s , y − t )
• The pixels having a D4 distance less than some r from (x,y) • The pixels having a D8 distance less than some r from (x,y)
form a diamond centered at (x,y) form a square centered at (x,y)
• Example: pixels where D4 ≤ 2 • Example: pixels where D8 ≤ 2

2 22222
2 1 2 Note: Pixels with D4=1 21112 Note: Pixels with D8=1
2 1 0 1 2 are the 4-neighbors 21012 are the 8-neighbors
2 1 2 of (x,y) 21112 of (x,y)
2 22222
Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-3 Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-4

Distance measures and connectivity Distance measures and m-connectivity

• The D4 distance between two points p and q is the shortest


4-path between the two points p3 p4
• The D8 distance between two points p and q is the shortest p1 p2
8-path between the two points p
• D4 and D8 may be considered, regardless of whether a
connected path exists between them, because the definition • Consider the given arrangement of pixels and assume
– p, p2 and p4 =1
of these distances involves only the pixel coordinates
– p1 and p3 can be 0 or 1
• For m-connectivity, the value of the distance (the length of
the path) between two points depends on the values of the • If V={1} and p1 and p3 are 0, the m-distance (p, p4) is 2
pixels along the path • If either p1 or p3 are 1, the m-distance (p, p4) is 3
• If p1 and p3 are 1, the m-distance (p, p4) is 4

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-5 Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-6
M-connectivity example Arithmetic & logic operations

• Arithmetic & logic operations on images used extensively in


most image processing applications
0 1 0 1 1 1
– May cover the entire image or a subset

0 1 1 1 1 1 • Arithmetic operation between pixels p and q are defined as:


– Addition: (p+q)
1 1 1 • Used often for image averaging to reduce noise
– Subtraction: (p-q)
• Used often for static background removal
m-distance(p,p4)=2 m-distance(p,p4)=3 m-distance(p,p4)=4
– Multiplication: (p*q) (or pq, p×q)
• Used to correct gray-level shading
– Division: (p÷q) (or p/q)
• As in multiplication

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-7 Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-8

Logic operations Examples of logic operations

• Arithmetic operation between pixels p and q are defined as:


A NOT(A)
– AND: pANDq (also p⋅q)
– OR: pORq (also p+q)
– COMPLEMENT: NOTq (also q’)
• Form a functionally complete set
A B (A) AND (B)
• Applicable to binary images
• Basic tools in binary image processing, used for:
– Masking
– Feature detection
A B (A) OR (B)
– Shape analysis

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-9 Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-10

Examples of logic operations (continued) Neighborhood-oriented operations

• Arithmetic and logical operations may take place on


a subset of the image
A B (A) XOR (B) – Typically neighborhood oriented
• Formulated in the context of mask operations (also
called template, window or filter operations)
• Basic concept: let the value of a pixel be a function
A B [NOT (A)] AND (B) of its (current) gray level and the gray level of its
neighbors (in some sense)

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-11 Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-12
Neighborhood-oriented operations Neighborhood-oriented operations
(continued) (continued)

• Consider the following subset of • In the more general form, the


pixels in an image operation may look like:
• Suppose we want to filter the 9 Z1 Z2 Z3
z = ( w1 z1 + w2 z2 + ... + w9 z9 ) = ∑ wi zi
image by replacing the value at i =1 Z4 Z5 Z6
Z5 with the average value of the Z1 Z2 Z3 • This equation is widely used in Z7 Z8 Z9
pixels in a 3x3 region centered image processing
around Z5
Z4 Z5 Z6
• Proper selection of coefficients
• Perform an operation of the form: Z7 Z8 Z9
(weights) allows for operations
1 1 9 such as W1 W2 W3
z = ( z1 + z 2 + ... + z9 ) = ∑ zi
9 9 i =1 – noise reduction W4 W5 W6
– region thinning
• and assign to z5 the value of z – edge detection W7 W8 W9

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-13 Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-14

Sample filtered image Sample filtered image

• The sample image was


filtered using a 3x3 basic • The sample image was
high pass filter as follows: filtered using a 3x3 basic
low pass filter as follows:
⎡− 1 − 1 − 1⎤
1⎢ ⎡1 1 1⎤
− 1 8 − 1⎥⎥ 1⎢
9⎢ 1 1 1⎥⎥
⎢⎣− 1 − 1 − 1⎥⎦ 9⎢
⎢⎣1 1 1⎥⎦

• Result showing filtered


image
• Result showing highlighted
edges in the image

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-15 Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-16

Sample filtered image Basic matlab instructions

• Sample matlab source files and data files available


• The sample image was
via website
filtered using a 5x5 basic
low pass filter as follows: – bmpread.m: A matlab source file which will load a
windows bitmap file into an array (256 color maximum)
⎡1 1 1 1 1⎤ • Format:
⎢1 1 1 1 1⎥⎥ [A_NAME,CMAP_NAME]=bmpread(‘filename’);
1 ⎢ – Creates an array (with name A_NAME) to hold the pixel data
⎢1 1 1 1 1⎥ – Creates a colormap (with name CMAP_NAME)
25 ⎢ ⎥
⎢1 1 1 1 1⎥ – bmpwrite.m: A matlab source file which will save an
⎢⎣1 1 1 1 1⎥⎦ array to a windows bitmap file (256 color maximum)
• Format:
• Result showing filtered bmpwrite(A_NAME, CMAP_NAME,’filename’);
image
Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-17 Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-18
Basic matlab instructions (continued)

• colormap(CMAP_NAME); Use a particular


colormap to display an image
• image(A_NAME); create and display an image
from a given array of data

Electrical & Computer Engineering Dr. D. J. Jackson Lecture 3-19

Вам также может понравиться