GradientOperator2d computes a first order derivative in each image axis direction.
To minimize the effect of noise, the algorithm can be combined with a smoothing filter for
computing the gradient. A smoothing scale parameter determines the smoothing intensity.
If its value is large, noise is reduced but edges are less sharp and
only the most significant edges are revealed (this behavior is reversed
for the Shen and Castan algorithm). It is important to select the right
coefficient to lower the noise just enough without defocusing the edges.
Finally the algorithm optionally computes the magnitude of the gradient vectors
either by selecting its maximum component or its Euclidean norm.
The following algorithms are proposed to extract the edges of an image:
Canny-Deriche: It performs a recursive gradient computation with an IIR
(Infinite Impulse Response) filter by derivating the Deriche [1] smoothing filter
which has the two-dimensional form:
f(x,y)=b2(α|x|+1)e−α|x|⋅(α|y|+1)e−α|y|whereb=α4
For color images, the magnitude is computed with the maximum of intensity or the Euclidean mean
of the color components.
Shen-Castan: It calculates the gradient of Shen and Castan [2]. It is
a recursive and exponential filter that smooths an object and then extracts
its edges. It is based on the Shen operator:
f(x,y)=p24e(−p(|x|+|y|)) The highest p is, the more edges we get. For color images the magnitude is computed with the maximum of
intensity or the Euclidean mean of the color components.
Canny: It is similar to Canny-Deriche but using a FIR (finite impulse response) filter [3].
It performs an approximation to get the Canny-Deriche in X
and Y directions using a convolution kernel 7x5 for X and 5x7 for Y.
The result is nearly the same as Canny-Deriche, but the process is much faster.
Gaussian: It performs a convolution with the derivatives of a Gaussian
function along each image axis.
Sobel: It performs a convolution with the Sobel Kernel. It cannot be applied on color images.
Gx=[−10+1−20+2−10+1]andGy=[−1−2−1000+1+2+1]
Prewitt: It performs a convolution with the Prewitt Kernel. It cannot be applied on color images.
Gx=[−10+1−10+1−10+1]andGy=[−1−1−1000+1+1+1]
Notices:
The output data type is determined by applying the Basic rules
defined for arithmetic operations.
To limit overflows, some normalizations are applied with most of the proposed operators by dividing the
output gray levels by the sum of absolute values of the kernel coefficients.
The Prewitt and Sobel operators do not apply normalizations and are thus inclined to produce overflows.
By default, the maximum component of each directional gradient is computed. Depending on the selected
operator, other output can be selected such as the Euclidean norm or the gradient components.
The smoothing factor has a totally different meaning depending on the selected gradient operator.
It represents a smoothing percentage with Canny-Deriche, a sharpenness factor with Shen and Castan,
a standard-deviation with the Gaussian and is ignored with Canny, Sobel and Prewitt.
References [1] R.Deriche. "Using Canny's criteria to derive a recursively implemented optimal edge detector".
International Journal of Computer Vision, vol.1, no 2, pp. 167-187, Jun. 1987.
[2] J.Shen, S.Castan. "An optimal linear operator for step edge detection". CVGIP : Graphical Models
and Image Processing, vol.54, no 2, pp. 112-133, Mar. 1992.
[3] J.F.Canny. "A computational approach to edge detection." IEEE Transactions on Pattern Analysis
and Machine Intelligence, vol.8, No 6, pp. 679-698, Nov. 1986.
/// Output structure of the GradientOperator2d function.publicstructGradientOperator2dOutput{/// The X-gradient output image.publicIOLink.ImageView outputImageX;/// The Y-gradient output image.publicIOLink.ImageView outputImageY;/// The gradient amplitude output image.publicIOLink.ImageView outputAmplitudeImage;/// The gradient orientation output image.publicIOLink.ImageView outputOrientationImage;};// Function prototype.publicstaticGradientOperator2dOutputGradientOperator2d(IOLink.ImageView inputImage,GradientOperator2d.GradientOperator gradientOperator =ImageDev.GradientOperator2d.GradientOperator.CANNY_DERICHE,GradientOperator2d.GradientMode gradientMode =ImageDev.GradientOperator2d.GradientMode.AMPLITUDE_MAXIMUM,double smoothingFactor =60,IOLink.ImageView outputImageX =null,IOLink.ImageView outputImageY =null,IOLink.ImageView outputAmplitudeImage =null,IOLink.ImageView outputOrientationImage =null);
Class Syntax
// Command constructor.GradientOperator2d();/// Gets the inputImage parameter./// The input image.
std::shared_ptr< iolink::ImageView> inputImage()const;/// Sets the inputImage parameter./// The input image.void setInputImage( std::shared_ptr< iolink::ImageView> inputImage );/// Gets the gradientOperator parameter./// The gradient operator to apply.GradientOperator2d::GradientOperator gradientOperator()const;/// Sets the gradientOperator parameter./// The gradient operator to apply.void setGradientOperator(constGradientOperator2d::GradientOperator& gradientOperator );/// Gets the gradientMode parameter./// The output image to compute.GradientOperator2d::GradientMode gradientMode()const;/// Sets the gradientMode parameter./// The output image to compute.void setGradientMode(constGradientOperator2d::GradientMode& gradientMode );/// Gets the smoothingFactor parameter./// The smoothing factor defines the gradient sharpness. It is only used with Canny Deriche, Shen Castan, and Gaussian operators. It has a totally different meaning depending on the selected gradient operator. Its value must be between 0 and 100.double smoothingFactor()const;/// Sets the smoothingFactor parameter./// The smoothing factor defines the gradient sharpness. It is only used with Canny Deriche, Shen Castan, and Gaussian operators. It has a totally different meaning depending on the selected gradient operator. Its value must be between 0 and 100.void setSmoothingFactor(constdouble& smoothingFactor );/// Gets the outputImageX parameter./// The X-gradient output image.
std::shared_ptr< iolink::ImageView> outputImageX()const;/// Sets the outputImageX parameter./// The X-gradient output image.void setOutputImageX( std::shared_ptr< iolink::ImageView> outputImageX );/// Gets the outputImageY parameter./// The Y-gradient output image.
std::shared_ptr< iolink::ImageView> outputImageY()const;/// Sets the outputImageY parameter./// The Y-gradient output image.void setOutputImageY( std::shared_ptr< iolink::ImageView> outputImageY );/// Gets the outputAmplitudeImage parameter./// The gradient amplitude output image.
std::shared_ptr< iolink::ImageView> outputAmplitudeImage()const;/// Sets the outputAmplitudeImage parameter./// The gradient amplitude output image.void setOutputAmplitudeImage( std::shared_ptr< iolink::ImageView> outputAmplitudeImage );/// Gets the outputOrientationImage parameter./// The gradient orientation output image.
std::shared_ptr< iolink::ImageView> outputOrientationImage()const;/// Sets the outputOrientationImage parameter./// The gradient orientation output image.void setOutputOrientationImage( std::shared_ptr< iolink::ImageView> outputOrientationImage );// Method to launch the command.void execute();
# Property of the inputImage parameter.GradientOperator2d.input_image
# Property of the gradientOperator parameter.GradientOperator2d.gradient_operator
# Property of the gradientMode parameter.GradientOperator2d.gradient_mode
# Property of the smoothingFactor parameter.GradientOperator2d.smoothing_factor
# Property of the outputImageX parameter.GradientOperator2d.output_image_x
# Property of the outputImageY parameter.GradientOperator2d.output_image_y
# Property of the outputAmplitudeImage parameter.GradientOperator2d.output_amplitude_image
# Property of the outputOrientationImage parameter.GradientOperator2d.output_orientation_image
// Method to launch the command.
execute()
// Command constructor.GradientOperator2d()// Property of the inputImage parameter.GradientOperator2d.inputImage
// Property of the gradientOperator parameter.GradientOperator2d.gradientOperator
// Property of the gradientMode parameter.GradientOperator2d.gradientMode
// Property of the smoothingFactor parameter.GradientOperator2d.smoothingFactor
// Property of the outputImageX parameter.GradientOperator2d.outputImageX
// Property of the outputImageY parameter.GradientOperator2d.outputImageY
// Property of the outputAmplitudeImage parameter.GradientOperator2d.outputAmplitudeImage
// Property of the outputOrientationImage parameter.GradientOperator2d.outputOrientationImage
// Method to launch the command.Execute()
Parameters
Parameter Name
Description
Type
Supported Values
Default Value
inputImage
The input image.
Image
Binary, Label, Grayscale or Multispectral
nullptr
gradientOperator
The gradient operator to apply.
CANNY_DERICHE
The gradient is computed using the Canny-Deriche algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
SHEN_CASTAN
The gradient is computed using the Shen and Castan algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM.
KERNEL3X3
The gradient is computed using the Sobel 3x3 kernel algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
CANNY
The gradient is computed using the Canny algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM and AMPLITUDE_EUCLIDEAN.
GAUSSIAN
The gradient is computed using the Gaussian algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
SOBEL
The gradient is computed using the Sobel algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
PREWITT
The gradient is computed using the Prewitt algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
Enumeration
CANNY_DERICHE
gradientMode
The output image to compute.
AMPLITUDE_MAXIMUM
This option computes the gradient maximal amplitude. Only the outputAmplitudeImage output is set using this mode.
AMPLITUDE_EUCLIDEAN
This option computes the gradient Euclidean amplitude. Only the outputAmplitudeImage output is set using this mode.
AMPLITUDE_AND_ORIENTATION
This option computes Euclidean amplitude and orientation in degrees (between -128 and +128 degrees). Both outputAmplitudeImage and outputOrientationImage outputs are set using this mode.
X_AND_Y_GRADIENTS
This option computes gradient in X and Y directions. Both outputImageX and outputImageY outputs are set using this mode.
Enumeration
AMPLITUDE_MAXIMUM
smoothingFactor
The smoothing factor defines the gradient sharpness. It is only used with Canny Deriche, Shen Castan, and Gaussian operators. It has a totally different meaning depending on the selected gradient operator. Its value must be between 0 and 100.
Canny-Deriche: it is inversely proportional to Deriche alpha smoothing factor, in pixels.
Low values provide sharp gradient. SmoothingFactor=(5.3−α)5×100
Shen And Castan: it is proportional to Shen Castan p smoothing factor, in pixels.
High values provide sharp gradient.
Gaussian: the Gaussian kernel standard deviation, in pixels. Low values provide sharp gradient.
Prewitt, Sobel, Canny: it is ignored.
Float64
]0, 100]
60
outputImageX
The X-gradient output image.
Image
nullptr
outputImageY
The Y-gradient output image.
Image
nullptr
outputAmplitudeImage
The gradient amplitude output image.
Image
nullptr
outputOrientationImage
The gradient orientation output image.
Image
nullptr
Parameter Name
Description
Type
Supported Values
Default Value
input_image
The input image.
image
Binary, Label, Grayscale or Multispectral
None
gradient_operator
The gradient operator to apply.
CANNY_DERICHE
The gradient is computed using the Canny-Deriche algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
SHEN_CASTAN
The gradient is computed using the Shen and Castan algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM.
KERNEL3X3
The gradient is computed using the Sobel 3x3 kernel algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
CANNY
The gradient is computed using the Canny algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM and AMPLITUDE_EUCLIDEAN.
GAUSSIAN
The gradient is computed using the Gaussian algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
SOBEL
The gradient is computed using the Sobel algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
PREWITT
The gradient is computed using the Prewitt algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
enumeration
CANNY_DERICHE
gradient_mode
The output image to compute.
AMPLITUDE_MAXIMUM
This option computes the gradient maximal amplitude. Only the outputAmplitudeImage output is set using this mode.
AMPLITUDE_EUCLIDEAN
This option computes the gradient Euclidean amplitude. Only the outputAmplitudeImage output is set using this mode.
AMPLITUDE_AND_ORIENTATION
This option computes Euclidean amplitude and orientation in degrees (between -128 and +128 degrees). Both outputAmplitudeImage and outputOrientationImage outputs are set using this mode.
X_AND_Y_GRADIENTS
This option computes gradient in X and Y directions. Both outputImageX and outputImageY outputs are set using this mode.
enumeration
AMPLITUDE_MAXIMUM
smoothing_factor
The smoothing factor defines the gradient sharpness. It is only used with Canny Deriche, Shen Castan, and Gaussian operators. It has a totally different meaning depending on the selected gradient operator. Its value must be between 0 and 100.
Canny-Deriche: it is inversely proportional to Deriche alpha smoothing factor, in pixels.
Low values provide sharp gradient. SmoothingFactor=(5.3−α)5×100
Shen And Castan: it is proportional to Shen Castan p smoothing factor, in pixels.
High values provide sharp gradient.
Gaussian: the Gaussian kernel standard deviation, in pixels. Low values provide sharp gradient.
Prewitt, Sobel, Canny: it is ignored.
float64
]0, 100]
60
output_image_x
The X-gradient output image.
image
None
output_image_y
The Y-gradient output image.
image
None
output_amplitude_image
The gradient amplitude output image.
image
None
output_orientation_image
The gradient orientation output image.
image
None
Parameter Name
Description
Type
Supported Values
Default Value
inputImage
The input image.
Image
Binary, Label, Grayscale or Multispectral
null
gradientOperator
The gradient operator to apply.
CANNY_DERICHE
The gradient is computed using the Canny-Deriche algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
SHEN_CASTAN
The gradient is computed using the Shen and Castan algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM.
KERNEL3X3
The gradient is computed using the Sobel 3x3 kernel algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
CANNY
The gradient is computed using the Canny algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM and AMPLITUDE_EUCLIDEAN.
GAUSSIAN
The gradient is computed using the Gaussian algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
SOBEL
The gradient is computed using the Sobel algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
PREWITT
The gradient is computed using the Prewitt algorithm. Supported gradient output modes : AMPLITUDE_MAXIMUM, AMPLITUDE_EUCLIDEAN, AMPLITUDE_AND_ORIENTATION and X_AND_Y_GRADIENTS.
Enumeration
CANNY_DERICHE
gradientMode
The output image to compute.
AMPLITUDE_MAXIMUM
This option computes the gradient maximal amplitude. Only the outputAmplitudeImage output is set using this mode.
AMPLITUDE_EUCLIDEAN
This option computes the gradient Euclidean amplitude. Only the outputAmplitudeImage output is set using this mode.
AMPLITUDE_AND_ORIENTATION
This option computes Euclidean amplitude and orientation in degrees (between -128 and +128 degrees). Both outputAmplitudeImage and outputOrientationImage outputs are set using this mode.
X_AND_Y_GRADIENTS
This option computes gradient in X and Y directions. Both outputImageX and outputImageY outputs are set using this mode.
Enumeration
AMPLITUDE_MAXIMUM
smoothingFactor
The smoothing factor defines the gradient sharpness. It is only used with Canny Deriche, Shen Castan, and Gaussian operators. It has a totally different meaning depending on the selected gradient operator. Its value must be between 0 and 100.
Canny-Deriche: it is inversely proportional to Deriche alpha smoothing factor, in pixels.
Low values provide sharp gradient. SmoothingFactor=(5.3−α)5×100
Shen And Castan: it is proportional to Shen Castan p smoothing factor, in pixels.
High values provide sharp gradient.
Gaussian: the Gaussian kernel standard deviation, in pixels. Low values provide sharp gradient.