Processing math: 76%
ImageDev

ArithmeticOperationWithImage

Performs a pointwise arithmetic operation between two images.

Access to parameter description

The arithmetic operator to apply between both input images I1 and I2 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 );

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 I1 and I2 is: O(n,m)=I1(n,m)+I2(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 I1 and I2 is: O(n,m)=I1(n,m)I2(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 I1 and I2 is: O(n,m)=I1(n,m)×I2(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 I1 and I2 is: O(n,m)=I1(n,m)÷I2(n,m)
    Remarks:
  • Overflows may occur.
  • Be careful with negative values and the way they are visualized.
  • If I2(n,m)=0 then O(n,m)=I1(n,m)
  • MINIMUM The MINIMUM arithmetic operator computes the minimum value between two images. The formula applied between both input images I1 and I2 is: O(n,m)=min
    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();

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