ImageDev

ArithmeticOperationWithImage

Performs a pointwise arithmetic operation between two images.

Access to parameter description

The arithmetic operator to apply between both input images $I_1$ and $I_2$ can be selected from: The type of the output image $O$ is deduced from the Rules for Arithmetic Image Type.

See also
See related example

Function Syntax

This function returns the outputImage output parameter.
// Function prototype.
std::shared_ptr< iolink::ImageView >
arithmeticOperationWithImage( std::shared_ptr< iolink::ImageView > inputImage1,
                              std::shared_ptr< iolink::ImageView > inputImage2,
                              ArithmeticOperationWithImage::ArithmeticOperator arithmeticOperator,
                              std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns the outputImage output parameter.
// Function prototype.
arithmetic_operation_with_image( input_image1,
                                 input_image2,
                                 arithmetic_operator = ArithmeticOperationWithImage.ArithmeticOperator.ADD,
                                 output_image = None )
This function returns the outputImage output parameter.
// Function prototype.
public static IOLink.ImageView
ArithmeticOperationWithImage( IOLink.ImageView inputImage1,
                              IOLink.ImageView inputImage2,
                              ArithmeticOperationWithImage.ArithmeticOperator arithmeticOperator = ImageDev.ArithmeticOperationWithImage.ArithmeticOperator.ADD,
                              IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Class Name ArithmeticOperationWithImage

Parameter Name Description Type Supported Values Default Value
input
inputImage1
The first input image.
The supported types for the first input image are grayscale, binary, label, and color.
Image Binary, Label, Grayscale or Multispectral nullptr
input
inputImage2
The second input image, must have same dimensions as the first input.
The supported types for the second input image are grayscale, binary, label, and color.
Image Binary, Label, Grayscale or Multispectral nullptr
input
arithmeticOperator
The arithmetic operator to apply.
ADD The ADD arithmetic operator adds an image to another. The formula applied between both input images $I_1$ and $I_2$ is: $$O(n,m)=I_1(n,m)+I_2(n,m)$$ Remarks:
  • Overflows may occur.
  • Be careful with negative values and the way they are visualized.
  • SUBTRACT The SUBTRACT arithmetic operator subtract an image from another. The formula applied between both input images $I_1$ and $I_2$ is: $$O(n,m)=I_1(n,m)-I_2(n,m)$$
    Remarks:
  • Overflows may occur.
  • The result of a subtraction between two binary images is a short integer image. This operation is not equivalent to a logical difference.
  • Be careful with negative values and the way they are visualized.
  • MULTIPLY The MULTIPLY arithmetic operator multiplies an image by another. The formula applied between both input images $I_1$ and $I_2$ is: $$O(n,m)=I_1(n,m) \times I_2(n,m)$$
    Remarks:
  • Overflows may occur.
  • Be careful with negative values and the way they are visualized.
  • Multiplying a binary image by a grayscale image is equivalent to a masking operation.
  • DIVIDE The DIVIDE arithmetic operator divides an image by another. The formula applied between both input images $I_1$ and $I_2$ is: $$O(n,m)=I_1(n,m)\div I_2(n,m)$$
    Remarks:
  • Overflows may occur.
  • Be careful with negative values and the way they are visualized.
  • If $I_2(n,m)=0$ then $O(n,m)=I_1(n,m)$
  • MINIMUM The MINIMUM arithmetic operator computes the minimum value between two images. The formula applied between both input images $I_1$ and $I_2$ is: $$O(n,m)=\min\left\{I_1(n,m),I_2(n,m)\right\}$$
    For binary images, the MINIMUM operator is equivalent to a logical AND. $$ \begin{array}{|c|c|c|} \hline I_1 & I_2 & I_1 \Lambda I_2\\ \hline 1 & 1 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 0 \\ \hline \end{array} $$
    MAXIMUM The MAXIMUM arithmetic operator computes the maximum value between two images. The formula applied between both input images $I_1$ and $I_2$ is: $$O(n,m)=\max\left\{I_1(n,m),I_2(n,m)\right\}$$
    For binary images, the MAXIMUM operator is equivalent to a logical OR. $$ \begin{array}{|c|c|c|} \hline I_1 & I_2 & I_1 \Delta I_2\\ \hline 1 & 1 & 1 \\ 1 & 0 & 1 \\ 0 & 1 & 1 \\ 0 & 0 & 0 \\ \hline \end{array} $$
    Enumeration ADD
    output
    outputImage
    The output image.
    The output image dimensions are forced to the same values as the inputs. The output image type is deduced from the inputs.
    Image nullptr

    Object Examples

    std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );
    
    ArithmeticOperationWithImage arithmeticOperationWithImageAlgo;
    arithmeticOperationWithImageAlgo.setInputImage1( polystyrene );
    arithmeticOperationWithImageAlgo.setInputImage2( polystyrene );
    arithmeticOperationWithImageAlgo.setArithmeticOperator( ArithmeticOperationWithImage::ArithmeticOperator::ADD );
    arithmeticOperationWithImageAlgo.execute();
    
    std::cout << "outputImage:" << arithmeticOperationWithImageAlgo.outputImage()->toString();
    
    polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))
    
    arithmetic_operation_with_image_algo = imagedev.ArithmeticOperationWithImage()
    arithmetic_operation_with_image_algo.input_image1 = polystyrene
    arithmetic_operation_with_image_algo.input_image2 = polystyrene
    arithmetic_operation_with_image_algo.arithmetic_operator = imagedev.ArithmeticOperationWithImage.ADD
    arithmetic_operation_with_image_algo.execute()
    
    print( "output_image:", str( arithmetic_operation_with_image_algo.output_image ) )
    
    ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );
    
    ArithmeticOperationWithImage arithmeticOperationWithImageAlgo = new ArithmeticOperationWithImage
    {
        inputImage1 = polystyrene,
        inputImage2 = polystyrene,
        arithmeticOperator = ArithmeticOperationWithImage.ArithmeticOperator.ADD
    };
    arithmeticOperationWithImageAlgo.Execute();
    
    Console.WriteLine( "outputImage:" + arithmeticOperationWithImageAlgo.outputImage.ToString() );
    

    Function Examples

    std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );
    
    auto result = arithmeticOperationWithImage( polystyrene, polystyrene, ArithmeticOperationWithImage::ArithmeticOperator::ADD );
    
    std::cout << "outputImage:" << result->toString();
    
    polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))
    
    result = imagedev.arithmetic_operation_with_image( polystyrene, polystyrene, imagedev.ArithmeticOperationWithImage.ADD )
    
    print( "output_image:", str( result ) )
    
    ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );
    
    IOLink.ImageView result = Processing.ArithmeticOperationWithImage( polystyrene, polystyrene, ArithmeticOperationWithImage.ArithmeticOperator.ADD );
    
    Console.WriteLine( "outputImage:" + result.ToString() );