60
CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) •edge/line detection

CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Embed Size (px)

Citation preview

Page 1: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

CGMB424: IMAGE PROCESSING AND COMPUTER VISION

image analysis (part 2)•edge/line detection

Page 2: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Overview

• Many edge and line detection are implemented with convolution masks, where most are based on discrete approximation to differential operators → measure the rate of change in image brightness function

• A large change in image brightness over a short spatial distance indicates the presence of an edge

• To detect line, first we need to detect the edge

– Mark edge points– Merge edge points to form lines and

object outlines

Page 3: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Problem in Edge and Line Detection• Noise in an image can create problem →

eliminate or at least minimize noise in an image

• Need to have tradeoff between sensitivity and accuracy of edge detector– Too sensitive → detect more noise points– Less sensitive → might miss valid edges– Larger mask → less sensitive to noise

– Lower grey level threshold → reduce noise effects

Page 4: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection

• It based on the idea of what relation that a pixel has with its neighbors

• If a pixel’s grey level value is similar to those around it → most probably, there is no edge

• If a pixel has neighbors with large difference in grey level value → it may represent an edge

Page 5: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection

• Types of edges– Ideal edge

• Has abrupt changes in brightness• The edge appears very distinct

– Real edge• Brightness changes gradually• The gradual changes is a minor form of

blurring caused by the imaging device → imaging device, lenses, lighting, etc

Page 6: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection

brightness

Spatial coordinates

brightness

Spatial coordinates

Ideal edge Real edge

Page 7: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Roberts Operator• Mark edge points only; does not return any information

about the edge orientation• The simplest and oldest method of edge detection• Work best with binary images• There are two forms to calculate the magnitude of the

edge– The square root of the sum of the diagonal neighbors

squared– The sum of the magnitude of the difference of the

diagonal neighbors• The second form of the equation is often used since it is

computational efficient• The disadvantage of Roberts Operator is that it is very

sensitive to noise

Page 8: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Roberts Operator

• The first form is√[I(r,c)-I(r-1,c-1)]2 + [I(r,c-1)-I(r-1,c)]2

• The second form is|I(r,c)-I(r-1,c-1)| + |I(r,c-1)-I(r-1,c)|

I (r,c)

Page 9: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Sobel Operator

• This operator looks for edges in both horizontal and vertical directions and then combine the information into a single metric

• Sobel operator is sensitive to high frequency noise• The mask

-1 -2 -1

0 0 0

1 2 1

-1 0 1

-2 0 2

-1 0 1Row mask Column mask

Page 10: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Sobel Operator

• After the convolution we will get 2 values – s1 → corresponding result from row mask

– s2 → corresponding result from column mask

• To get the edge magnitude√s1

2+s22

• To get the edge directions1

s2Tan-1

Page 11: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Prewitt Operator

• This operator is the same as Sobel, but using different mask coefficient

• The mask -1

-1

-1

0 0 0

1 1 1

-1 0 1

-1 0 1

-1 0 1Row mask Column mask

Effect of Horizontal

Prewitt mask

Effect of Vertical

Prewitt mask

Prewitt edge

magnitude

Image taken from http://ari.cankaya.edu.tr/~reza/ImLab4.htm

Page 12: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Prewitt Operator• After the convolution we will get 2 values

– p1 → corresponding result from row mask

– p2 → corresponding result from column mask

• To get the edge magnitude√p1

2+p22

• To get the edge directionp1

p2Tan-1

Page 13: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Kirsch Compass Masks

• Called compass masks because they are defined taking a single mask and rotating it to the eight major compass orientations

• The masks are as follows-3 -3 5

-3 0 5

-3 -3 5

-3 5 5

-3 0 5

-3 -3 -3

5 5 5

-3 0 -3

-3 -3 -3

5 5 -3

5 0 -3

-3 -3 -3

5 -3 -3

5 0 -3

5 -3 -3

-3 -3 -3

5 0 -3

5 5 -3

-3 -3 -3

-3 0 -3

5 5 5

-3 -3 -3

-3 0 5

-3 5 5

k0

k7k6k5k4

k3k2k1

Page 14: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Kirsch Compass Masks• The edge magnitude is defined as the

maximum value found by the convolution of the masks with the image

• The edge direction is defined by the mask that produces the maximum magnitude, e.g. k2 corresponds to the horizontal edge

• The last four masks are actually the same as first four, but flipped about a central axis

Page 15: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Robinson Compass Masks• Are used in similar manner as Kirsch

compass masks → easier because – rely on coefficient of 0, 1 and 2– Symmetrical about their directional axis

(axis with 0)

• We only need to compute the results of 4 of the masks, the other 4 can be obtained by negating the results from the first 4.

Page 16: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Robinson Compass Masks• The masks

-1 0 1

-2 0 2

-1 0 1

0 1 2

-1 0 1

-2

-1 0

1 2 1

0 0 0

-1

-2

-1

2 1 0

1 0-1

0-1

-2

1 0 -1

2 0 -2

1 0 -1

0-1 -2

1 0 -1

2 1 0

-1-2

-1

0 0 0

1 2 1

-2 -1 0

-1 0 1

0 1 2

r0

r7r6r5r4

r3r2r1

Page 17: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Robinson Compass Masks• The edge magnitude is defined by

the maximum value found by the convolution of edge of the masks with the image

• The edge direction is defined by the mask that produces the maximum magnitude

Page 18: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Laplacian Operators• There are 3 laplacian masks and each

represent different approximations of the laplacian operator

• The masks are rotationally symmetry• They are applied by selecting one mask

and convolving it with the image• The sign of the result (positive/negative)

from 2 adjacent pixel locations provides directional information and also tells us which side of the edge is brighter

Page 19: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Laplacian Operators

0 -1 0

-1 4 -1

0 -1 0

• The coefficient of the masks are all 0• This is to make sure at a region of interest with

constant value, it will return 0• If the coefficient is increased by 1, we will get the

original grey level• The larger the sum, the less the processed image

is changed from the original image

1 -2 1

-2 4 -2

1 -2 1

-1 -1 -1

-1 8 -1

-1 -1 -1Laplacian masks

Page 20: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Frei-Chen Masks• The masks form a complete set of

basic vectors → we can represent any 3X3 sub-image as a weighted sum of the 9 Frei-Chen masks

• These weights are found by projecting a 3X3 su-bimage onto each of these masks

• It is similar to convolution process

Page 21: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Frei-Chen Masks

1 √2 1

0 0 0

-1

- √2 -1

1 0 -1

√2 0

- √2

1 0 -1

0 -1 √2

1 0 -1

- √2 1 0

1 -2 1

-2 4 -2

1 -2 1

√2 -1 0

-1 0 1

0 1-

√2

0 1 0

-1 0 -1

0 1 0

-1 0 1

0 0 0

1 0 -1

-2 1 -2

1 4 1

-2 1 -2

1 1 1

1 1 1

1 1 1

12 √2

12 √2

12 √2

12 √2

12

16

16

12

13

f1 f2 f3

f4 f5f6

f7 f8 f9

Page 22: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Frei-Chen Masks

• Let say we have the following subimage1 -2 1

-2 4 -2

1 -2 1

– Start projecting the sub-image onto the masks

– Overlay the sub-image on the mask (in this case it is f1)

– Do normal convolution– Multiply the product of the convolution with 1/(2√2) factor1/(2√2)[1(1)+0(√2)+1(1)+1(0)+0(0)+1(0)+1(-1)+0(- √2)+1(-1)] = 0

– Keep on calculating until f9, and we will getf1→0, f2→0, f3→0, f4→0, f5→-1, f6→0, f7→0, f8→-1,f9→2

– Take the weights (non-zero) and multiply them by each mask; then sum the corresponding values

Is =

Page 23: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Frei-Chen Masks– Referring to the example, non-zero weights are at f5, f8

and f9

0 1 0

-1 0 -1

0 1 0

-2 1 -2

1 4 1

-2 1 -2

1 1 1

1 1 1

1 1 1

(-1)(1/2) +(-1)(1/6) +(2)(1/3)

1 0 1

1 0 1

1 0 1= = Is

– To be used for edge detection• Group frei-chen masks into a set of 4 masks for and edge

subspace, 4 masks for a line subspace and 1 mask for an average subspace

Page 24: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Detection Frei-Chen Masks– To use for edge detection, select a particular

subspace of interest and find the relative projection if the image onto the particular subspace by given equation

Cos Θ =MS√

– whereM = ∑ (Is,fk)2

kЄ{e}S = ∑ (Is,fk)2

k=1

9

– The set {e} consists of the masks of interest– The (Is,fk) notation refers to the process of overlaying the mask on the subimage, multiplying the coincident terms and summing the results

Page 25: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance

• In order to develop a performance metric for edge detector, we need to define:– What constitutes success– What types of errors can occur

• Types of error that can occur for edge detection– Missing valid edge points– Classifying noise pulses as valid edge points– Smearing edges

Page 26: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance

Real image

Noise misclassified as edge points

Missed edge points

Smeared edge

Page 27: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance Pratt Figure of Metric Rating Factor

FI

iN dI

IR

121

1

IN = the maximum of II and IFII = the number of ideal edge points in the image

IF = the number of edge points found by the edge detector

= a scaling constant that can be adjusted to adjust the penalty for offset edgesd = the distance of a found edge point to an ideal edge point

Page 28: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance Pratt Figure of Metric Rating Factor• For this metric, R will be 1 for a perfect

edge.• In general, this metric assigns a better

rating to smeared edges than to offset or missing edges.

• This is done because there exist techniques to thin smeared edges, but it is difficult to determine when an edge is missed.

Page 29: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance Pratt Figure of Metric Rating Factor• The objective metrics are often of

limited use in practical applications.• The subjective evaluation by human

visual system is still superior than any computer vision system.

Page 30: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance Edge Detection Examples

Original image Sobel Operator Prewitt Operator

Laplacian Operator Roberts Operator

Page 31: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance Edge Detection Examples

Page 32: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance Edge Detection Examples

Page 33: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance Edge Detection Examples

Page 34: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance Edge Detection Examples

Page 35: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance

• All operators return almost similar results except the laplacian operators.– Laplacian returns positive and negative

numbers that get linearly remapped to 0 to 255.

– The background value of 0 is mapped to some intermediate gray level.

• Only the magnitude is used for displaying the results.

Page 36: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance

• If we add noise to the image, the results are not as good.

• There are a number of ways to solve this:– Preprocess the image with spatial filters

to remove the noise.– Expand the edge detection operators.

Page 37: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance

1110111

1110111

1110111

1110111

1110111

1110111

1110111

1112111

1112111

1112111

0000000

1112111

1112111

1112111

Extended Prewitt Edge Detection Mask

Extended Sobel Edge DetectionMask

Page 38: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance

• We can also define a truncated pyramid operator.

• This operator provides weights that decrease as we get away from the center pixel.

1110111

1220221

1230321

1230321

1230321

1220221

1110111

Page 39: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance Edge Detection Examples - Noise

Page 40: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance Edge Detection Examples - Noise

Page 41: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance Edge Detection Examples - Noise

Page 42: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance Edge Detection Examples - Noise

Page 43: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Edge Operators Performance

• On images with noise, the extended operators exhibit better performance than the 3x3 masks.

• However, they have a number of setbacks:– Requires more computation.– Tends to slightly blur the edges.

Page 44: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

• Hough transform is used to find lines.• A line is defined as a collection of

edge points that are adjacent and have the same direction.

• Hough transform will take a collection of edge points found by an edge detector, and find all the lines on which these edge points lie.

Page 45: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

• In order to understand Hough transform, consider the normal (perpendicular) representation of a line:– ρ = r cos θ + c sin θ

• Each pair of ρ and θ corresponds to a possible line equation.– The range of θ is 90o

– The range of ρ is from 0 to 2N (N is image size)

Page 46: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

Page 47: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

• A line is a path where points that lie on it have the same direction (share the same line equation).

• The idea is to find the number of points that lie in each possible line within an image plane.

• The line that accommodates the most points shall be the candidate line.

Page 48: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

• However, in practical, there tend to be many lines.– Therefore, in practice, a line is selected if the

number of points that lie on it is more than certain threshold (user-defined).

• We cannot have infinite precision for ρ and θ or we will have infinite line equations.– Therefore, we need to quantize the ρθ

parameter space.

Page 49: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

Page 50: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

• Each block in the quantized space corresponds to a line, or group of possible lines.

• The algorithm used for Hough Transform consists of three primary steps:– Define the desired increments on ρ and

θ, Δρ and Δθ, and quantize the space accordingly.

Page 51: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

– For every point of interest (edge points), plug the values for r and c into the line equation:

ρ = r cos θ + c sin θ Then, for each value of θ in the quantized space, solve for ρ.

– For each ρθ pair from step 2, record the rc pair in the corresponding block in the quantized space. This constitutes a hit for that particular block.

Page 52: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

• When this process is completed, the number of hits in each block corresponds to the number of pixels on the line as defined by the values ρ and θ in that block.

• Next, select a threshold and select the quantization blocks that contain more points than the threshold.

Page 53: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

• When this process is completed, the lines are marked in the output image.

• There is a tradeoff in choosing the size of the quantization blocks:– Large blocks will reduce search time.– However, it may reduce the line

resolution in the image space.

Page 54: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

Page 55: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

Page 56: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

Page 57: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough Transform

Page 58: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough TransformExample

• Consider three data points, shown here as black dots.

Page 59: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough TransformExample• For each data point, a number of lines are plotted

going through it, all at different angles. These are shown here as solid lines.

• For each solid line a line is plotted which is perpendicular to it and which intersects the origin. These are shown as dashed lines.

• The length and angle of each dashed line is measured. In the diagram above, the results are shown in tables.

• This is repeated for each data point. • A graph of length against angle, known as a

Hough space graph, is then created.

Page 60: CGMB424: IMAGE PROCESSING AND COMPUTER VISION image analysis (part 2) edge/line detection

Hough TransformExample

•The point where the lines intersect gives a distance and angle. •This distance and angle indicate the line which bisects the points being tested. •In the graph shown the lines intersect at the purple point; this corresponds to the solid purple line in the diagrams above, which bisects the three points