GradientOperator2d
Provides different algorithms to perform an edge detection based on the first derivative of a two-dimensional image.
Access to parameter description
For an introduction:
The following algorithms are proposed to extract the edges of an image:
[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.
See also
Access to parameter description
For an introduction:
- section Edge Detection
- section Gradient
- section Images Filters
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)=b^2(\alpha|x|+1)e^{-\alpha|x|}\cdot(\alpha|y|+1)e^{-\alpha|y|}~~where~~b=\frac{\alpha}{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)=\frac{p^2}{4} e^{(-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. $$ \mathbf{G_x} = \begin{bmatrix} -1 & 0 & +1 \\ -2 & 0 & +2 \\ -1 & 0 & +1 \end{bmatrix} \quad \mbox{and} \quad \mathbf{G_y} = \begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ +1 & +2 & +1 \end{bmatrix} $$
- Prewitt: It performs a convolution with the Prewitt Kernel. It cannot be applied on color images. $$ \mathbf{G_x} = \begin{bmatrix} -1 & 0 & +1 \\ -1 & 0 & +1 \\ -1 & 0 & +1 \end{bmatrix} \quad \mbox{and} \quad \mathbf{G_y} = \begin{bmatrix} -1 & -1 & -1 \\ 0 & 0 & 0 \\ +1 & +1 & +1 \end{bmatrix} $$
- 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.
[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.
See also
Function Syntax
This function returns a GradientOperator2dOutput structure containing the outputImageX, outputImageY, outputAmplitudeImage and outputOrientationImage output parameters.
// Output structure. struct GradientOperator2dOutput { std::shared_ptr< iolink::ImageView > outputImageX; std::shared_ptr< iolink::ImageView > outputImageY; std::shared_ptr< iolink::ImageView > outputAmplitudeImage; std::shared_ptr< iolink::ImageView > outputOrientationImage; }; // Function prototype. GradientOperator2dOutput gradientOperator2d( std::shared_ptr< iolink::ImageView > inputImage, GradientOperator2d::GradientOperator gradientOperator, GradientOperator2d::GradientMode gradientMode, double smoothingFactor, std::shared_ptr< iolink::ImageView > outputImageX = NULL, std::shared_ptr< iolink::ImageView > outputImageY = NULL, std::shared_ptr< iolink::ImageView > outputAmplitudeImage = NULL, std::shared_ptr< iolink::ImageView > outputOrientationImage = NULL );
This function returns a tuple containing the output_image_x, output_image_y, output_amplitude_image and output_orientation_image output parameters.
// Function prototype. gradient_operator_2d( input_image, gradient_operator = GradientOperator2d.GradientOperator.CANNY_DERICHE, gradient_mode = GradientOperator2d.GradientMode.AMPLITUDE_MAXIMUM, smoothing_factor = 60, output_image_x = None, output_image_y = None, output_amplitude_image = None, output_orientation_image = None )
This function returns a GradientOperator2dOutput structure containing the outputImageX, outputImageY, outputAmplitudeImage and outputOrientationImage output parameters.
/// Output structure of the GradientOperator2d function. public struct GradientOperator2dOutput { public IOLink.ImageView outputImageX; public IOLink.ImageView outputImageY; public IOLink.ImageView outputAmplitudeImage; public IOLink.ImageView outputOrientationImage; }; // Function prototype. public static GradientOperator2dOutput GradientOperator2d( 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
Parameters
Class Name | GradientOperator2d |
---|
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.
|
Enumeration | CANNY_DERICHE | ||||||||||||||||
gradientMode |
The output image to compute.
|
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.
|
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 |
Object Examples
std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" ); GradientOperator2d gradientOperator2dAlgo; gradientOperator2dAlgo.setInputImage( polystyrene ); gradientOperator2dAlgo.setGradientOperator( GradientOperator2d::GradientOperator::CANNY_DERICHE ); gradientOperator2dAlgo.setGradientMode( GradientOperator2d::GradientMode::AMPLITUDE_MAXIMUM ); gradientOperator2dAlgo.setSmoothingFactor( 60.0 ); gradientOperator2dAlgo.execute(); std::cout << "outputImageX:" << gradientOperator2dAlgo.outputImageX()->toString(); std::cout << "outputImageY:" << gradientOperator2dAlgo.outputImageY()->toString(); std::cout << "outputAmplitudeImage:" << gradientOperator2dAlgo.outputAmplitudeImage()->toString(); std::cout << "outputOrientationImage:" << gradientOperator2dAlgo.outputOrientationImage()->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif")) gradient_operator_2d_algo = imagedev.GradientOperator2d() gradient_operator_2d_algo.input_image = polystyrene gradient_operator_2d_algo.gradient_operator = imagedev.GradientOperator2d.CANNY_DERICHE gradient_operator_2d_algo.gradient_mode = imagedev.GradientOperator2d.AMPLITUDE_MAXIMUM gradient_operator_2d_algo.smoothing_factor = 60.0 gradient_operator_2d_algo.execute() print( "output_image_x:", str( gradient_operator_2d_algo.output_image_x ) ); print( "output_image_y:", str( gradient_operator_2d_algo.output_image_y ) ); print( "output_amplitude_image:", str( gradient_operator_2d_algo.output_amplitude_image ) ); print( "output_orientation_image:", str( gradient_operator_2d_algo.output_orientation_image ) );
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" ); GradientOperator2d gradientOperator2dAlgo = new GradientOperator2d { inputImage = polystyrene, gradientOperator = GradientOperator2d.GradientOperator.CANNY_DERICHE, gradientMode = GradientOperator2d.GradientMode.AMPLITUDE_MAXIMUM, smoothingFactor = 60.0 }; gradientOperator2dAlgo.Execute(); Console.WriteLine( "outputImageX:" + gradientOperator2dAlgo.outputImageX.ToString() ); Console.WriteLine( "outputImageY:" + gradientOperator2dAlgo.outputImageY.ToString() ); Console.WriteLine( "outputAmplitudeImage:" + gradientOperator2dAlgo.outputAmplitudeImage.ToString() ); Console.WriteLine( "outputOrientationImage:" + gradientOperator2dAlgo.outputOrientationImage.ToString() );
Function Examples
std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" ); auto result = gradientOperator2d( polystyrene, GradientOperator2d::GradientOperator::CANNY_DERICHE, GradientOperator2d::GradientMode::AMPLITUDE_MAXIMUM, 60.0 ); std::cout << "outputImageX:" << result.outputImageX->toString(); std::cout << "outputImageY:" << result.outputImageY->toString(); std::cout << "outputAmplitudeImage:" << result.outputAmplitudeImage->toString(); std::cout << "outputOrientationImage:" << result.outputOrientationImage->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif")) result_output_image_x, result_output_image_y, result_output_amplitude_image, result_output_orientation_image = imagedev.gradient_operator_2d( polystyrene, imagedev.GradientOperator2d.CANNY_DERICHE, imagedev.GradientOperator2d.AMPLITUDE_MAXIMUM, 60.0 ) print( "output_image_x:", str( result_output_image_x ) ); print( "output_image_y:", str( result_output_image_y ) ); print( "output_amplitude_image:", str( result_output_amplitude_image ) ); print( "output_orientation_image:", str( result_output_orientation_image ) );
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" ); Processing.GradientOperator2dOutput result = Processing.GradientOperator2d( polystyrene, GradientOperator2d.GradientOperator.CANNY_DERICHE, GradientOperator2d.GradientMode.AMPLITUDE_MAXIMUM, 60.0 ); Console.WriteLine( "outputImageX:" + result.outputImageX.ToString() ); Console.WriteLine( "outputImageY:" + result.outputImageY.ToString() ); Console.WriteLine( "outputAmplitudeImage:" + result.outputAmplitudeImage.ToString() ); Console.WriteLine( "outputOrientationImage:" + result.outputOrientationImage.ToString() );