GradientMagnitude2d
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 outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > gradientMagnitude2d( std::shared_ptr< iolink::ImageView > inputImage, GradientMagnitude2d::GradientOperator gradientOperator, iolink::Vector2d standardDeviation, GradientMagnitude2d::FilterMode filterMode, GradientMagnitude2d::OutputType outputType, GradientMagnitude2d::GradientMode gradientMode, std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns outputImage.
// Function prototype. gradient_magnitude_2d( input_image, gradient_operator = GradientMagnitude2d.GradientOperator.GAUSSIAN, standard_deviation = [1, 1], filter_mode = GradientMagnitude2d.FilterMode.RECURSIVE, output_type = GradientMagnitude2d.OutputType.SAME_AS_INPUT, gradient_mode = GradientMagnitude2d.GradientMode.AMPLITUDE_EUCLIDEAN, output_image = None )
This function returns outputImage.
// Function prototype. public static IOLink.ImageView GradientMagnitude2d( IOLink.ImageView inputImage, GradientMagnitude2d.GradientOperator gradientOperator = ImageDev.GradientMagnitude2d.GradientOperator.GAUSSIAN, double[] standardDeviation = null, GradientMagnitude2d.FilterMode filterMode = ImageDev.GradientMagnitude2d.FilterMode.RECURSIVE, GradientMagnitude2d.OutputType outputType = ImageDev.GradientMagnitude2d.OutputType.SAME_AS_INPUT, GradientMagnitude2d.GradientMode gradientMode = ImageDev.GradientMagnitude2d.GradientMode.AMPLITUDE_EUCLIDEAN, IOLink.ImageView outputImage = 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 | SAME_AS_INPUT | ||||||||
gradientMode |
The output image to compute.
|
Enumeration | AMPLITUDE_EUCLIDEAN | ||||||||
outputImage |
The gradient amplitude output image.
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 | SAME_AS_INPUT | ||||||||
gradient_mode |
The output image to compute.
|
enumeration | AMPLITUDE_EUCLIDEAN | ||||||||
output_image |
The gradient amplitude output image.
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 | SAME_AS_INPUT | ||||||||
gradientMode |
The output image to compute.
|
Enumeration | AMPLITUDE_EUCLIDEAN | ||||||||
outputImage |
The gradient amplitude output image.
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" ); GradientMagnitude2d gradientMagnitude2dAlgo; gradientMagnitude2dAlgo.setInputImage( polystyrene ); gradientMagnitude2dAlgo.setGradientOperator( GradientMagnitude2d::GradientOperator::GAUSSIAN ); gradientMagnitude2dAlgo.setStandardDeviation( {1, 1} ); gradientMagnitude2dAlgo.setFilterMode( GradientMagnitude2d::FilterMode::RECURSIVE ); gradientMagnitude2dAlgo.setOutputType( GradientMagnitude2d::OutputType::SAME_AS_INPUT ); gradientMagnitude2dAlgo.setGradientMode( GradientMagnitude2d::GradientMode::AMPLITUDE_EUCLIDEAN ); gradientMagnitude2dAlgo.execute(); std::cout << "outputImage:" << gradientMagnitude2dAlgo.outputImage()->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif")) gradient_magnitude_2d_algo = imagedev.GradientMagnitude2d() gradient_magnitude_2d_algo.input_image = polystyrene gradient_magnitude_2d_algo.gradient_operator = imagedev.GradientMagnitude2d.GAUSSIAN gradient_magnitude_2d_algo.standard_deviation = [1, 1] gradient_magnitude_2d_algo.filter_mode = imagedev.GradientMagnitude2d.RECURSIVE gradient_magnitude_2d_algo.output_type = imagedev.GradientMagnitude2d.SAME_AS_INPUT gradient_magnitude_2d_algo.gradient_mode = imagedev.GradientMagnitude2d.AMPLITUDE_EUCLIDEAN gradient_magnitude_2d_algo.execute() print( "output_image:", str( gradient_magnitude_2d_algo.output_image ) )
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" ); GradientMagnitude2d gradientMagnitude2dAlgo = new GradientMagnitude2d { inputImage = polystyrene, gradientOperator = GradientMagnitude2d.GradientOperator.GAUSSIAN, standardDeviation = new double[]{1, 1}, filterMode = GradientMagnitude2d.FilterMode.RECURSIVE, outputType = GradientMagnitude2d.OutputType.SAME_AS_INPUT, gradientMode = GradientMagnitude2d.GradientMode.AMPLITUDE_EUCLIDEAN }; gradientMagnitude2dAlgo.Execute(); Console.WriteLine( "outputImage:" + gradientMagnitude2dAlgo.outputImage.ToString() );
Function Examples
std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" ); auto result = gradientMagnitude2d( polystyrene, GradientMagnitude2d::GradientOperator::GAUSSIAN, {1, 1}, GradientMagnitude2d::FilterMode::RECURSIVE, GradientMagnitude2d::OutputType::SAME_AS_INPUT, GradientMagnitude2d::GradientMode::AMPLITUDE_EUCLIDEAN ); std::cout << "outputImage:" << result->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif")) result = imagedev.gradient_magnitude_2d( polystyrene, imagedev.GradientMagnitude2d.GAUSSIAN, [1, 1], imagedev.GradientMagnitude2d.RECURSIVE, imagedev.GradientMagnitude2d.SAME_AS_INPUT, imagedev.GradientMagnitude2d.AMPLITUDE_EUCLIDEAN ) print( "output_image:", str( result ) )
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" ); IOLink.ImageView result = Processing.GradientMagnitude2d( polystyrene, GradientMagnitude2d.GradientOperator.GAUSSIAN, new double[]{1, 1}, GradientMagnitude2d.FilterMode.RECURSIVE, GradientMagnitude2d.OutputType.SAME_AS_INPUT, GradientMagnitude2d.GradientMode.AMPLITUDE_EUCLIDEAN ); Console.WriteLine( "outputImage:" + result.ToString() );