GradientVector2d
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:
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:
- Gaussian: It performs a convolution with the derivatives of a Gaussian function along each image axis.
- Sobel: It performs a convolution with the normalized Sobel Kernel: $$ \mathbf{G_x} = \frac{1}{8}\begin{bmatrix} -1 & 0 & 1 \\ -2 & 0 & 2 \\ -1 & 0 & 1 \end{bmatrix} \quad \mbox{and} \quad \mathbf{G_y} = \frac{1}{8}\begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ 1 & 2 & 1 \end{bmatrix} $$
- Prewitt: It performs a convolution with the normalized Prewitt Kernel: $$ \mathbf{G_x} = \frac{1}{6}\begin{bmatrix} -1 & 0 & 1 \\ -1 & 0 & 1 \\ -1 & 0 & 1 \end{bmatrix} \quad \mbox{and} \quad \mathbf{G_y} = \frac{1}{6}\begin{bmatrix} -1 & -1 & -1 \\ 0 & 0 & 0 \\ 1 & 1 & 1 \end{bmatrix} $$
See also
Function Syntax
This function returns a GradientVector2dOutput structure containing outputImageX and outputImageY.
// Output structure of the gradientVector2d function. struct GradientVector2dOutput { /// The gradient output image in X direction. std::shared_ptr< iolink::ImageView > outputImageX; /// The gradient output image in Y direction. std::shared_ptr< iolink::ImageView > outputImageY; }; // Function prototype
GradientVector2dOutput gradientVector2d( std::shared_ptr< iolink::ImageView > inputImage, GradientVector2d::GradientOperator gradientOperator, iolink::Vector2d standardDeviation, GradientVector2d::FilterMode filterMode, GradientVector2d::OutputType outputType, std::shared_ptr< iolink::ImageView > outputImageX = NULL, std::shared_ptr< iolink::ImageView > outputImageY = NULL );
This function returns a tuple containing output_image_x and output_image_y.
// Function prototype. gradient_vector_2d( input_image, gradient_operator = GradientVector2d.GradientOperator.GAUSSIAN, standard_deviation = [1, 1], filter_mode = GradientVector2d.FilterMode.RECURSIVE, output_type = GradientVector2d.OutputType.FLOAT_32_BIT, output_image_x = None, output_image_y = None )
This function returns a GradientVector2dOutput structure containing outputImageX and outputImageY.
/// Output structure of the GradientVector2d function. public struct GradientVector2dOutput { /// The gradient output image in X direction. public IOLink.ImageView outputImageX; /// The gradient output image in Y direction. public IOLink.ImageView outputImageY; }; // Function prototype. public static GradientVector2dOutput GradientVector2d( IOLink.ImageView inputImage, GradientVector2d.GradientOperator gradientOperator = ImageDev.GradientVector2d.GradientOperator.GAUSSIAN, double[] standardDeviation = null, GradientVector2d.FilterMode filterMode = ImageDev.GradientVector2d.FilterMode.RECURSIVE, GradientVector2d.OutputType outputType = ImageDev.GradientVector2d.OutputType.FLOAT_32_BIT, IOLink.ImageView outputImageX = null, IOLink.ImageView outputImageY = null );
Class Syntax
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.
|
Enumeration | GAUSSIAN | ||||||||||
standardDeviation |
The standard deviation of the gaussian operator defines the gradient sharpness. Low values provide sharp gradient.
This parameter is ignored with the Sobel and Prewitt gradient operators. |
Vector2d | >=0.1 | {1.f, 1.f} | |||||||||
filterMode |
The gradient operator to apply.
|
Enumeration | RECURSIVE | ||||||||||
outputType |
The output image type to provide.
|
Enumeration | FLOAT_32_BIT | ||||||||||
outputImageX |
The gradient output image in X direction.
Dimensions, calibration, and interpretation of the output image are forced to the same values as the input. |
Image | nullptr | ||||||||||
outputImageY |
The gradient output image in Y direction.
Dimensions, calibration, and interpretation of the output image are forced to the same values as the input. |
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.
|
enumeration | GAUSSIAN | ||||||||||
standard_deviation |
The standard deviation of the gaussian operator defines the gradient sharpness. Low values provide sharp gradient.
This parameter is ignored with the Sobel and Prewitt gradient operators. |
vector2d | >=0.1 | [1, 1] | |||||||||
filter_mode |
The gradient operator to apply.
|
enumeration | RECURSIVE | ||||||||||
output_type |
The output image type to provide.
|
enumeration | FLOAT_32_BIT | ||||||||||
output_image_x |
The gradient output image in X direction.
Dimensions, calibration, and interpretation of the output image are forced to the same values as the input. |
image | None | ||||||||||
output_image_y |
The gradient output image in Y direction.
Dimensions, calibration, and interpretation of the output image are forced to the same values as the input. |
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.
|
Enumeration | GAUSSIAN | ||||||||||
standardDeviation |
The standard deviation of the gaussian operator defines the gradient sharpness. Low values provide sharp gradient.
This parameter is ignored with the Sobel and Prewitt gradient operators. |
Vector2d | >=0.1 | {1f, 1f} | |||||||||
filterMode |
The gradient operator to apply.
|
Enumeration | RECURSIVE | ||||||||||
outputType |
The output image type to provide.
|
Enumeration | FLOAT_32_BIT | ||||||||||
outputImageX |
The gradient output image in X direction.
Dimensions, calibration, and interpretation of the output image are forced to the same values as the input. |
Image | null | ||||||||||
outputImageY |
The gradient output image in Y direction.
Dimensions, calibration, and interpretation of the output image are forced to the same values as the input. |
Image | null |
Object Examples
std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" ); GradientVector2d gradientVector2dAlgo; gradientVector2dAlgo.setInputImage( polystyrene ); gradientVector2dAlgo.setGradientOperator( GradientVector2d::GradientOperator::GAUSSIAN ); gradientVector2dAlgo.setStandardDeviation( {1, 1} ); gradientVector2dAlgo.setFilterMode( GradientVector2d::FilterMode::RECURSIVE ); gradientVector2dAlgo.setOutputType( GradientVector2d::OutputType::FLOAT_32_BIT ); gradientVector2dAlgo.execute(); std::cout << "outputImageX:" << gradientVector2dAlgo.outputImageX()->toString(); std::cout << "outputImageY:" << gradientVector2dAlgo.outputImageY()->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif")) gradient_vector_2d_algo = imagedev.GradientVector2d() gradient_vector_2d_algo.input_image = polystyrene gradient_vector_2d_algo.gradient_operator = imagedev.GradientVector2d.GAUSSIAN gradient_vector_2d_algo.standard_deviation = [1, 1] gradient_vector_2d_algo.filter_mode = imagedev.GradientVector2d.RECURSIVE gradient_vector_2d_algo.output_type = imagedev.GradientVector2d.FLOAT_32_BIT gradient_vector_2d_algo.execute() print( "output_image_x:", str( gradient_vector_2d_algo.output_image_x ) ) print( "output_image_y:", str( gradient_vector_2d_algo.output_image_y ) )
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" ); GradientVector2d gradientVector2dAlgo = new GradientVector2d { inputImage = polystyrene, gradientOperator = GradientVector2d.GradientOperator.GAUSSIAN, standardDeviation = new double[]{1, 1}, filterMode = GradientVector2d.FilterMode.RECURSIVE, outputType = GradientVector2d.OutputType.FLOAT_32_BIT }; gradientVector2dAlgo.Execute(); Console.WriteLine( "outputImageX:" + gradientVector2dAlgo.outputImageX.ToString() ); Console.WriteLine( "outputImageY:" + gradientVector2dAlgo.outputImageY.ToString() );
Function Examples
std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" ); auto result = gradientVector2d( polystyrene, GradientVector2d::GradientOperator::GAUSSIAN, {1, 1}, GradientVector2d::FilterMode::RECURSIVE, GradientVector2d::OutputType::FLOAT_32_BIT ); std::cout << "outputImageX:" << result.outputImageX->toString(); std::cout << "outputImageY:" << result.outputImageY->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif")) result_output_image_x, result_output_image_y = imagedev.gradient_vector_2d( polystyrene, imagedev.GradientVector2d.GAUSSIAN, [1, 1], imagedev.GradientVector2d.RECURSIVE, imagedev.GradientVector2d.FLOAT_32_BIT ) print( "output_image_x:", str( result_output_image_x ) ) print( "output_image_y:", str( result_output_image_y ) )
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" ); Processing.GradientVector2dOutput result = Processing.GradientVector2d( polystyrene, GradientVector2d.GradientOperator.GAUSSIAN, new double[]{1, 1}, GradientVector2d.FilterMode.RECURSIVE, GradientVector2d.OutputType.FLOAT_32_BIT ); Console.WriteLine( "outputImageX:" + result.outputImageX.ToString() ); Console.WriteLine( "outputImageY:" + result.outputImageY.ToString() );