ImageDev

GradientMagnitude3d

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: GradientMagnitude3d computes a first order derivative in each image axis direction and then computes the magnitude of the gradient vectors by selecting its maximum component or its Euclidean norm.

The following algorithms are proposed to extract the edges of an image:

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > gradientMagnitude3d( std::shared_ptr< iolink::ImageView > inputImage, GradientMagnitude3d::GradientOperator gradientOperator, iolink::Vector3d standardDeviation, GradientMagnitude3d::FilterMode filterMode, GradientMagnitude3d::OutputType outputType, GradientMagnitude3d::GradientMode gradientMode, std::shared_ptr< iolink::ImageView > outputImage = nullptr );
This function returns outputImage.
// Function prototype.
gradient_magnitude_3d(input_image: idt.ImageType,
                      gradient_operator: GradientMagnitude3d.GradientOperator = GradientMagnitude3d.GradientOperator.GAUSSIAN,
                      standard_deviation: Union[Iterable[int], Iterable[float]] = [1, 1, 1],
                      filter_mode: GradientMagnitude3d.FilterMode = GradientMagnitude3d.FilterMode.RECURSIVE,
                      output_type: GradientMagnitude3d.OutputType = GradientMagnitude3d.OutputType.SAME_AS_INPUT,
                      gradient_mode: GradientMagnitude3d.GradientMode = GradientMagnitude3d.GradientMode.AMPLITUDE_EUCLIDEAN,
                      output_image: idt.ImageType = None) -> idt.ImageType
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
GradientMagnitude3d( IOLink.ImageView inputImage,
                     GradientMagnitude3d.GradientOperator gradientOperator = ImageDev.GradientMagnitude3d.GradientOperator.GAUSSIAN,
                     double[] standardDeviation = null,
                     GradientMagnitude3d.FilterMode filterMode = ImageDev.GradientMagnitude3d.FilterMode.RECURSIVE,
                     GradientMagnitude3d.OutputType outputType = ImageDev.GradientMagnitude3d.OutputType.SAME_AS_INPUT,
                     GradientMagnitude3d.GradientMode gradientMode = ImageDev.GradientMagnitude3d.GradientMode.AMPLITUDE_EUCLIDEAN,
                     IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Image Binary, Label, Grayscale or Multispectral nullptr
input
gradientOperator
The gradient operator to apply.
GAUSSIAN The gradient is computed by convolution with the derivative of a Gaussian filter.
SOBEL The gradient is computed using the Sobel algorithm.
PREWITT The gradient is computed using the Prewitt algorithm.
Enumeration GAUSSIAN
input
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.
Vector3d >=0.1 {1.f, 1.f, 1.f}
input
filterMode
The gradient operator to apply.
FINITE This mode uses a Finite Impulse Response algorithm on the X, Y and Z directions. This mode is faster for small standard deviation values. The kernel size value is four times the standard deviation and cannot be smaller than 5.
RECURSIVE This mode uses an Infinite Impulse Response algorithm on the X, Y and Z directions. The computation time is constant with this implementation. This mode is more precise for computing the Gaussian filter.
Enumeration RECURSIVE
input
outputType
The output image type to provide.
SAME_AS_INPUT The output image has same type as the input image. In the case of integer images, this mode can lead to a loss of precision.
FLOAT_32_BIT The output image type is forced to floating point.
Enumeration SAME_AS_INPUT
input
gradientMode
The output image to compute.
AMPLITUDE_MAXIMUM This option computes the amplitude as the maximum between the X and Y components.
AMPLITUDE_EUCLIDEAN This option computes the Euclidean norm of the vector.
Enumeration AMPLITUDE_EUCLIDEAN
output
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
input_image
The input image. image Binary, Label, Grayscale or Multispectral None
input
gradient_operator
The gradient operator to apply.
GAUSSIAN The gradient is computed by convolution with the derivative of a Gaussian filter.
SOBEL The gradient is computed using the Sobel algorithm.
PREWITT The gradient is computed using the Prewitt algorithm.
enumeration GAUSSIAN
input
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.
vector3d >=0.1 [1, 1, 1]
input
filter_mode
The gradient operator to apply.
FINITE This mode uses a Finite Impulse Response algorithm on the X, Y and Z directions. This mode is faster for small standard deviation values. The kernel size value is four times the standard deviation and cannot be smaller than 5.
RECURSIVE This mode uses an Infinite Impulse Response algorithm on the X, Y and Z directions. The computation time is constant with this implementation. This mode is more precise for computing the Gaussian filter.
enumeration RECURSIVE
input
output_type
The output image type to provide.
SAME_AS_INPUT The output image has same type as the input image. In the case of integer images, this mode can lead to a loss of precision.
FLOAT_32_BIT The output image type is forced to floating point.
enumeration SAME_AS_INPUT
input
gradient_mode
The output image to compute.
AMPLITUDE_MAXIMUM This option computes the amplitude as the maximum between the X and Y components.
AMPLITUDE_EUCLIDEAN This option computes the Euclidean norm of the vector.
enumeration AMPLITUDE_EUCLIDEAN
output
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
input
inputImage
The input image. Image Binary, Label, Grayscale or Multispectral null
input
gradientOperator
The gradient operator to apply.
GAUSSIAN The gradient is computed by convolution with the derivative of a Gaussian filter.
SOBEL The gradient is computed using the Sobel algorithm.
PREWITT The gradient is computed using the Prewitt algorithm.
Enumeration GAUSSIAN
input
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.
Vector3d >=0.1 {1f, 1f, 1f}
input
filterMode
The gradient operator to apply.
FINITE This mode uses a Finite Impulse Response algorithm on the X, Y and Z directions. This mode is faster for small standard deviation values. The kernel size value is four times the standard deviation and cannot be smaller than 5.
RECURSIVE This mode uses an Infinite Impulse Response algorithm on the X, Y and Z directions. The computation time is constant with this implementation. This mode is more precise for computing the Gaussian filter.
Enumeration RECURSIVE
input
outputType
The output image type to provide.
SAME_AS_INPUT The output image has same type as the input image. In the case of integer images, this mode can lead to a loss of precision.
FLOAT_32_BIT The output image type is forced to floating point.
Enumeration SAME_AS_INPUT
input
gradientMode
The output image to compute.
AMPLITUDE_MAXIMUM This option computes the amplitude as the maximum between the X and Y components.
AMPLITUDE_EUCLIDEAN This option computes the Euclidean norm of the vector.
Enumeration AMPLITUDE_EUCLIDEAN
output
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

auto foam = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "foam.vip" );

GradientMagnitude3d gradientMagnitude3dAlgo;
gradientMagnitude3dAlgo.setInputImage( foam );
gradientMagnitude3dAlgo.setGradientOperator( GradientMagnitude3d::GradientOperator::GAUSSIAN );
gradientMagnitude3dAlgo.setStandardDeviation( {1, 1, 1} );
gradientMagnitude3dAlgo.setFilterMode( GradientMagnitude3d::FilterMode::RECURSIVE );
gradientMagnitude3dAlgo.setOutputType( GradientMagnitude3d::OutputType::SAME_AS_INPUT );
gradientMagnitude3dAlgo.setGradientMode( GradientMagnitude3d::GradientMode::AMPLITUDE_EUCLIDEAN );
gradientMagnitude3dAlgo.execute();

std::cout << "outputImage:" << gradientMagnitude3dAlgo.outputImage()->toString();
foam = imagedev.read_vip_image(imagedev_data.get_image_path("foam.vip"))

gradient_magnitude_3d_algo = imagedev.GradientMagnitude3d()
gradient_magnitude_3d_algo.input_image = foam
gradient_magnitude_3d_algo.gradient_operator = imagedev.GradientMagnitude3d.GAUSSIAN
gradient_magnitude_3d_algo.standard_deviation = [1, 1, 1]
gradient_magnitude_3d_algo.filter_mode = imagedev.GradientMagnitude3d.RECURSIVE
gradient_magnitude_3d_algo.output_type = imagedev.GradientMagnitude3d.SAME_AS_INPUT
gradient_magnitude_3d_algo.gradient_mode = imagedev.GradientMagnitude3d.AMPLITUDE_EUCLIDEAN
gradient_magnitude_3d_algo.execute()

print("output_image:", str(gradient_magnitude_3d_algo.output_image))
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" );

GradientMagnitude3d gradientMagnitude3dAlgo = new GradientMagnitude3d
{
    inputImage = foam,
    gradientOperator = GradientMagnitude3d.GradientOperator.GAUSSIAN,
    standardDeviation = new double[]{1, 1, 1},
    filterMode = GradientMagnitude3d.FilterMode.RECURSIVE,
    outputType = GradientMagnitude3d.OutputType.SAME_AS_INPUT,
    gradientMode = GradientMagnitude3d.GradientMode.AMPLITUDE_EUCLIDEAN
};
gradientMagnitude3dAlgo.Execute();

Console.WriteLine( "outputImage:" + gradientMagnitude3dAlgo.outputImage.ToString() );

Function Examples

auto foam = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "foam.vip" );

auto result = gradientMagnitude3d( foam, GradientMagnitude3d::GradientOperator::GAUSSIAN, {1, 1, 1}, GradientMagnitude3d::FilterMode::RECURSIVE, GradientMagnitude3d::OutputType::SAME_AS_INPUT, GradientMagnitude3d::GradientMode::AMPLITUDE_EUCLIDEAN );

std::cout << "outputImage:" << result->toString();
foam = imagedev.read_vip_image(imagedev_data.get_image_path("foam.vip"))

result = imagedev.gradient_magnitude_3d(foam, imagedev.GradientMagnitude3d.GAUSSIAN, [1, 1, 1], imagedev.GradientMagnitude3d.RECURSIVE, imagedev.GradientMagnitude3d.SAME_AS_INPUT, imagedev.GradientMagnitude3d.AMPLITUDE_EUCLIDEAN)

print("output_image:", str(result))
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" );

IOLink.ImageView result = Processing.GradientMagnitude3d( foam, GradientMagnitude3d.GradientOperator.GAUSSIAN, new double[]{1, 1, 1}, GradientMagnitude3d.FilterMode.RECURSIVE, GradientMagnitude3d.OutputType.SAME_AS_INPUT, GradientMagnitude3d.GradientMode.AMPLITUDE_EUCLIDEAN );

Console.WriteLine( "outputImage:" + result.ToString() );