Class CannyEdgeDetector
- java.lang.Object
-
- edu.gsu.cs.dmlab.imageproc.edgedetection.CannyEdgeDetector
-
- All Implemented Interfaces:
IEdgeDetector
public class CannyEdgeDetector extends Object implements IEdgeDetector
This class was originally implemented by Tom Gibara, which can be found in CannyEdgeDetector.java. In addition, the wiki page of Canny Edge Detector can also be useful.
This class provides a configurable implementation of the Canny edge detection algorithm. This classic algorithm has a number of shortcomings, but remains an effective tool in many scenarios.
- Author:
- Tom Gibara, modified by Azim Ahmadzadeh and Dustin Kempton, Data Mining Lab, Georgia State University
-
-
Constructor Summary
Constructors Constructor Description CannyEdgeDetector(double lowThreshold, double highThreshold, double gaussianKernelRadius, int gaussianKernelWidth, boolean contrastNormalized)
Constructor of a new detector object with the passed in parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double[][]
getEdges(double[][] sourceImage, double[] colors)
This method extracts the edges of the given image by following the following three steps: 1) Compute gradient, 2) Perform Hysteresis, 3) Thresholding.double[]
getFinalMagnitude()
void
thresholdEdges(int picsize, double[] data, double[] cols)
It replaces any zero values withcols[0]
, and any non-zero positive values withcols[1]
.
-
-
-
Constructor Detail
-
CannyEdgeDetector
public CannyEdgeDetector(double lowThreshold, double highThreshold, double gaussianKernelRadius, int gaussianKernelWidth, boolean contrastNormalized)
Constructor of a new detector object with the passed in parameters.- Parameters:
lowThreshold
- The low threshold for hysteresis. Suitable values for this parameter must be determined experimentally for each application. It is nonsensical (though not prohibited) for this value to exceed the high threshold value.
Suggested value: 2.5fhighThreshold
- The high threshold for hysteresis. Suitable values for this parameter must be determined experimentally for each application. It is nonsensical (though not prohibited) for this value to be less than the low threshold value.
Suggested value: 7.5fgaussianKernelRadius
- The radius of the Gaussian convolution kernel used to smooth the source image prior to gradient calculation.
Suggested value: 2fgaussianKernelWidth
- The number of pixels across which the Gaussian kernel is applied. This implementation will reduce the radius if the contribution of pixel values is deemed negligible, so this is actually a maximum radius.
Suggested value: 16contrastNormalized
- Whether the luminance data extracted from the source image is normalized by linearizing its histogram prior to edge extraction. Suggested value: false
note: KeepcontrastNormalized = false
since this part is not implemented.
-
-
Method Detail
-
getEdges
public double[][] getEdges(double[][] sourceImage, double[] colors)
Description copied from interface:IEdgeDetector
This method extracts the edges of the given image by following the following three steps: 1) Compute gradient, 2) Perform Hysteresis, 3) Thresholding.- Specified by:
getEdges
in interfaceIEdgeDetector
- Parameters:
sourceImage
- The source image whose edges are to be extracted.colors
- An array of length two that specofies the background and edge color of the finla results. The first cell carries the background color intensity and its second cell carries the foreground color intensity. (Examples: new double{0.0, 255.0})- Returns:
- A 2D binary array representing the edges and the background.
-
thresholdEdges
public void thresholdEdges(int picsize, double[] data, double[] cols)
It replaces any zero values withcols[0]
, and any non-zero positive values withcols[1]
.- Parameters:
picsize
- the size of the image in a 1D array.data
- the background (i.e.,cols[0]
) and foreground (i.e.,cols[1]
) color intensities used for showing the detected edges.
-
getFinalMagnitude
public double[] getFinalMagnitude()
-
-