Sei sulla pagina 1di 24

CHAPTER 1

INTRODUCTION
The edge detection process serves to simplify the analysis of images by drastically
reducing the amount of data to be processed, while at the same time preserving useful structural
information about object boundaries. There is certainly a great deal of diversity in the
applications of edge detection, but it is felt that many applications share a common set of
requirements. These requirements yield an abstract edge detection problem, the solution of which
can be applied in any of the original problem domains.
We define detection and localization criteria for a class of edges, and present
mathematical forms for these criteria as functional on the operator impulse response. On
specializing the analysis to step edges, we find that there is a natural uncertainty principle
between detection and localization performance, which are the two main goals.
The Canny edge detection method is one such optimal technique. The optimal detector
has a simple approximate implementation in which edges are marked at maxima in gradient
magnitude of a Gaussian-smoothed image. We extend this simple detector using operators of
several widths to cope with different signal-to-noise ratios in the image. We present a general
method, called feature synthesis, for the fine-to-coarse integration of information from operators
at different scales. Finally we show that step edge detector performance improves considerably
as the operator point spread function is extended along the edge.

1.1 Types of Edge Detection Technique


1.1.1 Sobel Operator
The operator consists of a pair of 33 convolution kernels. One kernel is simply the other rotated
by 90.
Gx=[-1 0 1;-2 0 2;-1 0 1]
Gy=[-1 -2 -1;0 0 0;1 2 1]

These kernels are designed to respond maximally to edges running vertically and horizontally
relative to the pixel grid, one kernel for each of the two perpendicular orientations. The kernels
can be applied separately to the input image, to produce separate measurements of the gradient
component in each orientation (call these Gx and Gy). These can then be combined together to
1

find the absolute magnitude of the gradient at each point and the orientation of that gradient. The
gradient magnitude is given by:
|G| =(Gx^2+Gy^2)^(1/2)
Typically, an approximate magnitude is computed using:
|G| = |Gx| + |Gy|
which is much faster to compute.
The angle of orientation of the edge (relative to the pixel grid) giving rise to the spatial gradient
is given by:
arctan(Gy /Gx)
1.1.2 Roberts cross operator:
The Roberts Cross operator performs a simple, quick to compute, 2-D spatial gradient
measurement on an image. Pixel values at each point in the output represent the estimated
absolute magnitude of the spatial gradient of the input image at that point. The operator consists
of a pair of 22 convolution kernels as shown. One kernel is simply the other rotated by 90.
This is very similar to the Sobel operator.
Gx=[1 0;0 -1]
Gy=[0 1;-1 0]
These kernels are designed to respond maximally to edges running at 45 to the pixel grid, one
kernel for each of the two perpendicular orientations. The kernels can be applied separately to
the input image, to produce separate measurements of the gradient component in each orientation
(call these Gx and Gy). These can then be combined together to find the absolute magnitude of
the gradient at each point and the orientation of that gradient. The gradient magnitude is given
by:
|G| =(Gx^2+Gy^2)^(1/2)
although typically, an approximate magnitude is computed using:
|G| = |Gx| + |Gy|
2

which is much faster to compute.


The angle of orientation of the edge giving rise to the spatial gradient (relative to the pixel grid
orientation) is given by:
arctan(Gy /Gx)-3/ 4
1.1.3 Prewitts operator:
Prewitt operator is similar to the Sobel operator and is used for detecting vertical and horizontal
edges in images.
Gx=[-1 0 +1:-1 0 +1:-1 0 +1]
Gy=[+1 +1 +1;0 0 0;-1 -1 -1]

1.1.4 Laplacian of Gaussian:


The Laplacian is a 2-D isotropic measure of the 2nd spatial derivative of an image. The
Laplacian of an image highlights regions of rapid intensity change and is therefore often used for
edge detection. Laplacian is often applied to an image that has first been smoothed with
something approximating a Gaussian Smoothing filter in order to reduce its sensitivity to noise.
The operator normally takes a single gray level image as input and produces another gray level
image as output.

Since the input image is represented as a set of discrete pixels, we have to find a discrete
convolution kernel that can approximate the second derivatives in the definition of the Laplacian.
1.1.5 Canny Edge Detection Technique
The purpose of edge detection in general is to significantly reduce the amount of data in an
image, while preserving the structural properties to be used for further image processing. Several
algorithms exists. The Canny edge detection technique was given by John F. Canny (JFC) in
1986 . Even though it is quite old, it has become one of the standard edge detection methods and
it is still used in research.

The aim of JFC was to develop an algorithm that is optimal with regards to the following
criteria:

1. Detection: The probability of detecting real edge points should be maximized while the
probability of falsely detecting non-edge points should be minimized. This corresponds to
maximizing the signal-to-noise ratio.

2. Localization: The detected edges should be as close as possible to the real edges.

3. Number of responses: One real edge should not result in more than one detected edge (one can
argue that this is implicitly included in the first requirement).
Thus with JFCs mathematical formulation of these criteria, Cannys Edge Detector is
optimal for a certain class of edges (known as step edges). The image intensity from one value
tone side of the discontinuity to a different value on opposite side.

Canny preprocessing includes:


Determining ROI (Region of Interest) that includes only white background besides the
pump, and cropping the image to this region.

Conversion to gray-scale to limit the computational requirements.

Histogram-stretching, so that the image uses the entire gray-scale. This step may not be
necessary, but it is included to counter-compensate for automatic light adjustment in the used
web camera.

The algorithm runs in 5 separate steps:


1. Smoothing: Blurring of the image to remove noise.
2. Finding gradients: The edges should be marked where the gradients of the image has large
magnitudes.
3. Non-maximum suppression: Only local maxima should be marked as edges.
4. Double thresholding: Potential edges are determined by thresholding.
5. Edge tracking by hysteresis: Final edges are determined by suppressing all edges that are not
connected to a very certain (strong) edge.

Smoothing
It is inevitable that all images taken from a camera will contain some amount of noise. To
prevent that noise is mistaken for edges, noise must be reduced. Therefore the image is first
smoothed by applying a Gaussian filter. The kernel of a Gaussian filter with a standard deviation
of sigma = 1.4 is as following:
B=(1/159)*[2 4 5 4 2;4 9 12 9 4;5 12 15 12 5;4 9 12 9 4;2 4 5 4 2]

Finding gradients
The Canny algorithm basically finds edges where the grayscale intensity of the image changes
the most. These areas are found by determining gradients of the image. Gradients at each pixel in
the smoothed image are determined by applying what is known as the Sobel-operator. First step
is to approximate the gradient in the x- and y-direction respectively by applying the kernels as
shown
Kx=[-1 0 1;-2 0 2;-1 0 1]
Ky=[-1 -2 -1;0 0 0;1 2 1]

The gradient magnitudes (also known as the edge strengths) can then be determined as an
Euclidean distance measure by applying the law of Pythagoras. It is sometimes simplified by
applying Manhattan distance measure as shown below to reduce the computational complexity.
The Euclidean distance measure has been applied to the test image. The computed edge strengths
are compared to the smoothed image.
|G| =(Gx^2+Gy^2)^(1/2)
|G| = |Gx| + |Gy|
where:
Gx and Gy are the gradients in the x- and y-directions respectively.

An image of the gradient magnitudes often indicate the edges quite clearly. However, the edges
are typically broad and thus do not indicate exactly where the edges are. So to make it possible to
determine this, the direction of the edges must be determined and stored.
5

Theta=arctan(|Gy|/|Gx|)

Non-maximum suppression
The purpose of this step is to convert the blurred edges in the image of the gradient magnitudes
to sharp edges. Basically this is done by preserving all local maxima in the gradient image, and
deleting everything else. The algorithm is for each pixel in the gradient image:
1. Round the gradient direction _ to nearest 45, corresponding to the use of an 8-connected
neighbourhood.
2. Compare the edge strength of the current pixel with the edge strength of the pixel in the
positive and negative gradient direction. I.e. if the gradient direction is north (theta = 90),
compare with the pixels to the north and south.
3. If the edge strength of the current pixel is largest; preserve the value of the edge strength. If
not, suppress (i.e. remove) the value. A simple example of non-maximum suppression. Almost all
pixels have gradient directions pointing north. They are therefore compared with the pixels
above and below. The pixels that turn out to be maximal in this comparison are marked with
white borders. All other pixels will be suppressed The edge-pixels remaining after the nonmaximum suppression step are (still) marked with their strength pixel-by-pixel. Many of these
will probably be true edges in the image, but some may be caused by noise or color variations for
instance due to rough surfaces. The simplest way to discern between these would be to use a
threshold, so that only edges stronger that a certain value would be preserved. The Canny edge
detection algorithm uses double thresholding. Edge pixels stronger than the high threshold are
marked as strong; edge pixels weaker than the low threshold are suppressed and edge pixels
between the two thresholds are marked as weak. Edges with a strength below both thresholds are
suppressed.
Edge tracking by hysteresis
Strong edges are interpreted as certain edges, and can immediately be included in the final
edge image. Weak edges are included if and only if they are connected to strong edges. The logic
is of course that noise and other small variations are unlikely to result in a strong edge (with
proper adjustment of the threshold levels). Thus strong edges will (almost) only be due to true
edges in the original image. The weak edges can either be due to true edges or noise/color
variations. The latter type will probably be distributed independently of edges on the entire
image, and thus only a small amount will be located adjacent to strong edges. Weak edges due to
true edges are much more likely to be connected directly to strong edges.

Edge tracking can be implemented by BLOB-analysis (Binary Large OBject). The edge pixels
are divided into connected BLOBs using 8-connected neighbourhood. BLOBs containing at
least one strong edge pixel are then preserved, while other BLOBs are suppressed. The effect of
edge tracking on the test image. First all weak edges are scanned for neighbor edges and joined
into groups. At the same time it is marked which groups are adjacent. Then all of these markings
are examined to determine which groups of weak edges are connected to strong edges (directly
or indirectly). All weak edges that are connected to strong edges are marked as strong edges
themselves. The rest of the weak edges are suppressed. This can be interpreted as BLOB analysis
where only BLOBs containing strong edges are preserved (and considered as one BLOB).

1.2 PROJECT OBJECTVE


The purpose of this project is to optimize the parameters of Canny edge detection and to
find out the results which are relatively comparable and efficient just like pre-defined Canny
technique. The work is carried on MATLAB tool (R2009b) and the algorithm is implemented on
it and results are analyzed. The approach is as followed:

Studying the classical Canny method in-depth.


Defining optimal range of sigma for efficient detection of edges with minimum effect of
noise.
Plotting results for change in parameters and comparing its results with classical Canny
technique.

1.3 SUMMARY
The Canny algorithm goes through five steps to give an edge detected image as final
output. So here we are varying some of the parameters in the classical canny such as standard
deviation, mask value, threshold levels etc.
The results obtained are represented in graphical form as well as in the form of images and
compared with results that are obtained using predefined canny method. The results are found to
be comparable with those of classical approach. Also an optimal range of operation is found.

CHAPTER 2
LITERATURE SURVEY AND PROBLEM FORMULATION

2.1 Literature Survey


A Computational Approach to Edge Detection
JOHN CANNY, MEMBER, IEEE
The success of the approach depends on the definition of a comprehensive set of goals for
the computation of edge points. These goals must be precise enough to delimit the desired
behavior of the detector while making minimal assumptions about the form of the solution. We
define detection and localization criteria for a class of edges, and present mathematical forms for
these criteria as functional on the operator impulse response. A third criterion is then added to
ensure that the detector has only one response to- a single edge. We use the criteria in numerical
optimization to derive detectors for several common image features, including step edges. On
specializing the analysis to step edges, we find that there is a natural uncertainty principle
between detection and localization performance, which are the two main goals. With this
principle we derive a single operator shape which is optimal at any scale. The optimal detector
has a simple approximate implementation in which edges are marked at maxima in gradient
magnitude of a Gaussian-smoothed image. We extend this simple detector using operators of
several widths to cope with different signal-to-noise ratios in the image. We present a general
method, called feature synthesis, for the fine-to-coarse integration of information from operators
at different scales. Finally we show that step edge detector performance improves considerably
as the operator point spread function is extended along the edge. This detection scheme uses
several elongated operators at each point, and the directional operator outputs are integrated with
the gradient maximum detector.
The design was based on the specification of detection and localization criteria in a mathematical
form. It was necessary to augment the original two criteria with a multiple response measure in
order to fully capture the intuition of good detection.
Directional edges numerical optimization was used to find optimal operators for roof and ridge
edges. The analysis was then restricted to consideration of optimal operators for step edges. The
result was a class of operators related by spatial scaling. There was a direct tradeoff in detection
performance versus localization, and this was determined by the spatial A detector was proposed
which used adaptive thresholding with hysteresis to eliminate streaking of edge contours.

10

The thresholds were set according to the amount of noise in the image, as determined by a noise
estimation scheme. This detector made use of several operator widths to cope with varying image
signal-to-noise ratios, and operator outputs were combined using a method called feature
synthesis, where the responses of the smaller operators were used to predict the large operator
responses. If the actual large operator outputs differ significantly from the predicted values, new
edge points are marked. It is therefore possible to describe edges that occur at different scales,
even if they are spatially coincident. In two dimensions it was shown that marking edge points at
maxima of gradient magnitude in the gradient direction is equivalent to finding zero-crossings of
a certain nonlinear differential operator. It was shown that when edge contours are locally
straight, highly directional operators will give better results than operators with a circular
support. A method was proposed for the efficient generation of highly directional masks at
several orientations and their integration into a single description.
Among the possible extensions of the work, the most interesting unsolved problem is the
integration of different edge detector outputs into a single description. A scheme which combined
the edge and ridge detector outputs using feature synthesis was implemented, but the results were
inconclusive. The problem is much more complicated here than for edge operators at different
scales because there is no clear reason to prefer one edge type over another. Each edge set must
be synthesized from the other, without a bias caused by overestimation in one direction. The
criteria we have presented can be used with slight modification for the design of other kinds of
operator. There is a natural generalization to the detection of higher-dimensional edges, such as
occur at material boundaries in tomographic scans. Gaussian convolution can be broken down
into n linear convolutions.

11

2.2 Problem Formulation


The classical Canny was implemented on some fixed parameters such as standard
deviation=1.4 and mask size of 5*5 which limits working range and also does not suppress noise
as per user application sometimes. Also the threshold level calculated is same throughout the
image which causes the loss of significant edge data in the distinct foreground and background
part of images.

12

2.3 Proposed Solution


The solution can be done by designing of Gaussian kernel for the user defined value of
standard deviation. The second problem of global thresholding can be solved by using the
adaptive approach of calculating threshold locally at each pixel.

13

CHAPTER 3
RELEVENT TO PROJECT

3.1 Method used for the project


3.1.1 Gaussian blur
A Gaussian blur (also known as Gaussian smoothing) is the result of blurring an image
by a Gaussian function. It is a widely used effect in graphics software, typically to reduce image
noise and reduce detail. The visual effect of this blurring technique is a smooth blur resembling
that of viewing the image through a translucent screen, distinctly different from the bokeh effect
produced by an out-of-focus lens or the shadow of an object under usual illumination. Gaussian
smoothing is also used as a pre-processing stage in computer vision algorithms in order to
enhance image structures at different scales.

Mathematically, applying a Gaussian blur to an image is the same as convolving the image with
a Gaussian function. This is also known as a two-dimensional Weierstrass transform. By
contrast, convolving by a circle (i.e., a circular box blur) would more accurately reproduce
the bokeh effect. Since the Fourier transform of a Gaussian is another Gaussian, applying a
Gaussian blur has the effect of reducing the image's high-frequency components; a Gaussian blur
is thus a low pass filter.

The Gaussian blur is a type of image-blurring filter that uses a Gaussian function (which also
expresses the normal distribution in statistics) for calculating the transformation to apply to each
pixel in the image. The equation of a Gaussian function in one dimension is

in two dimensions, it is the product of two such Gaussians, one in each dimension:

where x is the distance from the origin in the horizontal axis, y is the distance from the origin in
the vertical axis, and is the standard deviation of the Gaussian distribution. When applied in
14

two dimensions, this formula produces a surface whose contours are concentric circles with a
Gaussian distribution from the center point. Values from this distribution are used to build
a convolution matrix which is applied to the original image. Each pixel's new value is set to
a weighted average of that pixel's neighborhood. The original pixel's value receives the heaviest
weight (having the highest Gaussian value) and neighboring pixels receive smaller weights as
their distance to the original pixel increases. This results in a blur that preserves boundaries and
edges better than other, more uniform blurring filters

This is the first step of Canny algorithm. The classical Canny approach uses a mask of size 5*5
at standard deviation=1.4. So to optimize noise the range of Canny we are varying value of
standard deviation. To observe the effect of Gaussian blur at different values of standard
deviation i.e. from .5 to 5, PSNR calculation is done and the simulation results of mse vs
sigma , psnr vs sigma and psnr vs mse are analyzed.

3.1.2 Adaptive thresholding


Thresholding is used to segment an image by setting all pixels whose intensity
values are above a threshold to a foreground value and all the remaining pixels to a background
value.

The conventional thresholding operator uses a global threshold for all pixels, adaptive
thresholding changes the threshold dynamically over the image. This more sophisticated version
of thresholding can accommodate changing lighting conditions in the image, e.g. those occurring
as a result of a strong illumination gradient or shadows.

Adaptive thresholding typically takes a grayscale or color image as input and, in the simplest
implementation, outputs a binary image representing the segmentation. For each pixel in the
image, a threshold has to be calculated. If the pixel value is below the threshold it is set to the
background value, otherwise it assumes the foreground value.

There are two main approaches to finding the threshold: (i) the Chow and Kaneko approach and
(ii) local thresholding. The assumption behind both methods is that smaller image regions are
more likely to have approximately uniform illumination, thus being more suitable for
thresholding. Chow and Kaneko divide an image into an array of overlapping subimages and
then find the optimum threshold for each subimage by investigating its histogram. The threshold
15

for each single pixel is found by interpolating the results of the subimages. The drawback of this
method is that it is computational expensive and, therefore, is not appropriate for real-time
applications.

An alternative approach to finding the local threshold is to statistically examine the intensity
values of the local neighborhood of each pixel. The statistic which is most appropriate depends
largely on the input image. Simple and fast functions include the mean of the local intensity
distribution,

the median value,

or the mean of the minimum and maximum values,

The size of the neighborhood has to be large enough to cover sufficient foreground and
background pixels, otherwise a poor threshold is chosen. On the other hand, choosing regions
which are too large can violate the assumption of approximately uniform illumination. This
method is less computationally intensive than the Chow and Kaneko approach and produces
good results for some applications.

16

17

3.2 System GUI

Figure 1:System GUI

18

CHAPTER 4
SIMULATION AND RESULTS

4.1 MSE vs STANDARD DEVIATION PLOT

Figure 2: mse vs sigma

19

4.2 PSNR vs STANDARD DEVIATION PLOT

Figure 3: PSNR VS MSE

20

21

4.4 Software used


MATLAB is a high-level language and interactive environment for numerical
computation, visualization, and programming. Using MATLAB, you can analyze data, develop
algorithms, and create models and applications. The language, tools, and built-in math functions
enable you to explore multiple approaches and reach a solution faster than with spreadsheets or
traditional programming languages, such as C/C++ or Java.

You can use MATLAB for a range of applications, including signal processing and
communications, image and video processing, control systems, test and measurement,
computational finance, and computational biology. More than a million engineers and scientists
in industry and academia use MATLAB, the language of technical computing.

22

CHAPTER 5
CONCLUSION AND FUTURE SCOPE

5.1 Conclusion
The optimal range for edge detection can be taken as standard deviation. High
value of standard deviation will introduce large mask value resulting in higher convolution cost
and time. High intensity component which are significant data for edge detection will be
suppressed at higher value of standard deviation.

23

5.2 Future scope


An effective noise reduction algorithm can be added to the project which will
reduce and calculate the amount of noise in the image.

24

Potrebbero piacerti anche