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 the outputAmplitudeImage and outputOrientationImage output parameters.
// Output structure.
struct VectorToMagnitude2dOutput
{
    std::shared_ptr< iolink::ImageView > outputAmplitudeImage;
    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 );
This function returns a tuple containing the output_amplitude_image and output_orientation_image output parameters.
// Function prototype.
vector_to_magnitude_2d( input_image_x,
                        input_image_y,
                        output_type = VectorToMagnitude2d.OutputType.AMPLITUDE_MAXIMUM,
                        output_amplitude_image = None,
                        output_orientation_image = None )
This function returns a VectorToMagnitude2dOutput structure containing the outputAmplitudeImage and outputOrientationImage output parameters.
/// Output structure of the VectorToMagnitude2d function.
public struct VectorToMagnitude2dOutput
{
    public IOLink.ImageView outputAmplitudeImage;
    public IOLink.ImageView outputOrientationImage;
};

// Function prototype.
public static VectorToMagnitude2dOutput
VectorToMagnitude2d( IOLink.ImageView inputImageX,
                     IOLink.ImageView inputImageY,
                     VectorToMagnitude2d.OutputType outputType = ImageDev.VectorToMagnitude2d.OutputType.AMPLITUDE_MAXIMUM,
                     IOLink.ImageView outputAmplitudeImage = null,
                     IOLink.ImageView outputOrientationImage = null );

Class Syntax

Parameters

Class Name VectorToMagnitude2d

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();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))

vector_to_magnitude_2d_algo = imagedev.VectorToMagnitude2d()
vector_to_magnitude_2d_algo.input_image_x = polystyrene
vector_to_magnitude_2d_algo.input_image_y = polystyrene
vector_to_magnitude_2d_algo.output_type = imagedev.VectorToMagnitude2d.AMPLITUDE_MAXIMUM
vector_to_magnitude_2d_algo.execute()

print( "output_amplitude_image:", str( vector_to_magnitude_2d_algo.output_amplitude_image ) );
print( "output_orientation_image:", str( vector_to_magnitude_2d_algo.output_orientation_image ) );
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );

VectorToMagnitude2d vectorToMagnitude2dAlgo = new VectorToMagnitude2d
{
    inputImageX = polystyrene,
    inputImageY = polystyrene,
    outputType = VectorToMagnitude2d.OutputType.AMPLITUDE_MAXIMUM
};
vectorToMagnitude2dAlgo.Execute();

Console.WriteLine( "outputAmplitudeImage:" + vectorToMagnitude2dAlgo.outputAmplitudeImage.ToString() );
Console.WriteLine( "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();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))

result_output_amplitude_image, result_output_orientation_image = imagedev.vector_to_magnitude_2d( polystyrene, polystyrene, imagedev.VectorToMagnitude2d.AMPLITUDE_MAXIMUM )

print( "output_amplitude_image:", str( result_output_amplitude_image ) );
print( "output_orientation_image:", str( result_output_orientation_image ) );
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );

Processing.VectorToMagnitude2dOutput result = Processing.VectorToMagnitude2d( polystyrene, polystyrene, VectorToMagnitude2d.OutputType.AMPLITUDE_MAXIMUM );

Console.WriteLine( "outputAmplitudeImage:" + result.outputAmplitudeImage.ToString() );
Console.WriteLine( "outputOrientationImage:" + result.outputOrientationImage.ToString() );