ImageDev

VectorToMagnitude2d

Computes amplitude and orientation of a 2D vector such as a gradient from its X and Y components.

Access to parameter description

For an introduction to gradient operations: Gradient Section.

VectorToMagnitude2d extracts the Euclidean norm, maximum component or orientation of a 2D vector from its X and Y components.
It is typically used to compute the magnitude of a 2D image gradient.
The results depend on the selected output mode.

See also

Function Syntax

This function returns a VectorToMagnitude2dOutput structure containing outputAmplitudeImage and outputOrientationImage.
// Output structure of the vectorToMagnitude2d function.
struct VectorToMagnitude2dOutput
{
    /// The amplitude output image.
    std::shared_ptr< iolink::ImageView > outputAmplitudeImage;
    /// The orientation output image.
    std::shared_ptr< iolink::ImageView > outputOrientationImage;
};

// Function prototype
VectorToMagnitude2dOutput vectorToMagnitude2d( std::shared_ptr< iolink::ImageView > inputImageX, std::shared_ptr< iolink::ImageView > inputImageY, VectorToMagnitude2d::OutputType outputType, std::shared_ptr< iolink::ImageView > outputAmplitudeImage = NULL, std::shared_ptr< iolink::ImageView > outputOrientationImage = NULL );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImageX
The X vector component input image. Image Grayscale or Multispectral nullptr
input
inputImageY
The Y vector component input image. Image Grayscale or Multispectral nullptr
input
outputType
The output mode.
AMPLITUDE_MAXIMUM This option computes the amplitude as the maximum between the X and Y components. Only the outputAmplitudeImage output is set using this mode.
AMPLITUDE_EUCLIDEAN This option computes the Euclidean norm of the vector. Only the outputAmplitudeImage output is set using this mode.
AMPLITUDE_AND_ORIENTATION This option computes Euclidean norm and orientation in degrees (between -128 and +128 degrees). Both outputAmplitudeImage and outputOrientationImage outputs are set using this mode.
Enumeration AMPLITUDE_MAXIMUM
output
outputAmplitudeImage
The amplitude output image. Image nullptr
output
outputOrientationImage
The orientation output image. Image nullptr

Object Examples

std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

VectorToMagnitude2d vectorToMagnitude2dAlgo;
vectorToMagnitude2dAlgo.setInputImageX( polystyrene );
vectorToMagnitude2dAlgo.setInputImageY( polystyrene );
vectorToMagnitude2dAlgo.setOutputType( VectorToMagnitude2d::OutputType::AMPLITUDE_MAXIMUM );
vectorToMagnitude2dAlgo.execute();

std::cout << "outputAmplitudeImage:" << vectorToMagnitude2dAlgo.outputAmplitudeImage()->toString();
std::cout << "outputOrientationImage:" << vectorToMagnitude2dAlgo.outputOrientationImage()->toString();

Function Examples

std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

auto result = vectorToMagnitude2d( polystyrene, polystyrene, VectorToMagnitude2d::OutputType::AMPLITUDE_MAXIMUM );

std::cout << "outputAmplitudeImage:" << result.outputAmplitudeImage->toString();
std::cout << "outputOrientationImage:" << result.outputOrientationImage->toString();