ImageDev

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: GradientVector2d computes a first order derivative in each image axis direction.

The following algorithms are proposed to extract the edges of an image:
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

Class Name GradientVector2d

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.
Vector2d >=0.1 {1.f, 1.f}
input
filterMode
The gradient operator to apply.
FINITE This mode uses a Finite Impulse Response algorithm on the X and Y 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 and Y 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.
SIGNED_INTEGER_8_BIT The output image type is forced to 8-bit signed integer.
SIGNED_INTEGER_16_BIT The output image type is forced to 16-bit signed integer.
SIGNED_INTEGER_32_BIT The output image type is forced to 32-bit signed integer.
FLOAT_32_BIT The output image type is forced to 32-bit float.
Enumeration FLOAT_32_BIT
output
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
output
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

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() );