|
Part 2: Math, Math, Math
by James Antonakos
Start ý Blob
Analysis ý Edge DetectionýBehind the Mask
ý A Helping Hand from Fourier ý Please
Sir, May I Have Some More? ý Sources and
PDF
EDGE DETECTIONýBEHIND THE MASK
If your goal is to count all the blobs
that are present in an image (as in counting the number of red blood
cells or IC chips on an assembly line), the first step is to identifying
the edges of each object. An edge in an image is the boundary between
two significantly different pixel values (black to white or white
to black). So, you must search through the image looking for these
changes in order to identify edges. After they are found, the pixels
are modified so that the edge is enhanced and easily seen.
Photos 2aýc show horizontal edges, vertical
edges, and both horizontal and vertical edges, respectively. Notice
that horizontal edges do not have to be completely horizontal, simply
close enough to horizontal to be detected. The same is true for vertical
edges also.

a) |

b) |

c)
|
|
Photos 2aýcý(a)
is the result of applying a horizontal mask to the image.
Notice that all horizontal portions of the image have been
enhanced, while non-horizontal portions are barely visible.
(b) is the result of applying vertical mask to the image.
All non-vertical portions of the image are eliminated or reduced.
And, (c) is the result of applying the Sobel mask to the image.
All horizontal and vertical edges are enhanced. (click
to enlarge)
|
An easy way to detect edges in an image
is to use a 3 ý 3 matrix, or mask, of values that use pixels in the
neighborhood of the target pixel to affect how the pixel is modified.
Figures 3 and 4 show the mask values used for horizontal and vertical
edge detection. The corresponding 3 ý 3 array of pixel values (eight
pixels surrounding the center target pixel) are multiplied by the
numbers in the mask and added together, with the result replacing
the center pixel value. The masks are swiped over each pixel in a
row, generating a new line of pixels in the result image.
|
|
| Figure 3ýThe mask values for
horizontal edge detection can be seen here. |
Clearly, plenty of multiplication and
addition must be performed to generate the new image. In fact, nine
multiplies and eight additions are required for each pixel, giving
a total of almost 590,000 multiplies and 524,000 additions for a 256
ý 256 image.
|
|
| Figure 4ýThe mask values for
vertical edge detection can be seen here. |
Applying both of the masks
shown in Figures 3 and 4 to the image will reveal both horizontal
and vertical edges (as indicated in Photo 2c). Together, these two
operations make up the Sobel mask, just one of many different masks
used to enhance or alter an image.
PREVIOUS
NEXT
Circuit Cellar provides up-to-date information for engineers. Visit
www.circuitcellar.com for
more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com
or subscribe online.
ýCircuit Cellar, the Magazine for Computer Applications. Posted with
permission. |