ImageDev

ArithmeticOperationWithValue

Performs a pointwise arithmetic operation between an image and a value.

Access to parameter description

The arithmetic operator to apply between the input image $I$ and the constant value $C$ can be selected from: The type of the output image $O$ is deduced from the Rules for Arithmetic Image Type.

See also

Function Syntax

This function returns the outputImage output parameter.
// Function prototype.
std::shared_ptr< iolink::ImageView >
arithmeticOperationWithValue( std::shared_ptr< iolink::ImageView > inputImage,
                              double value,
                              ArithmeticOperationWithValue::ArithmeticOperator arithmeticOperator,
                              std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns the outputImage output parameter.
// Function prototype.
arithmetic_operation_with_value( input_image,
                                 value = 0,
                                 arithmetic_operator = ArithmeticOperationWithValue.ArithmeticOperator.ADD,
                                 output_image = None )
This function returns the outputImage output parameter.
// Function prototype.
public static IOLink.ImageView
ArithmeticOperationWithValue( IOLink.ImageView inputImage,
                              double value = 0,
                              ArithmeticOperationWithValue.ArithmeticOperator arithmeticOperator = ImageDev.ArithmeticOperationWithValue.ArithmeticOperator.ADD,
                              IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Class Name ArithmeticOperationWithValue

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image.
The image type can be grayscale, binary, label, and color.
Image Binary, Label, Grayscale or Multispectral nullptr
input
value
The value to apply.
The value is cast into the smallest type with no loss of precision.
Float64 Any value 0
input
arithmeticOperator
The arithmetic operator to apply.
ADD The ADD arithmetic operator adds an image I with a constant C. The formula applied between the input image $I$ and the operand $C$ is: $$O(n,m)=I(n,m)+C$$ Remarks:
  • Overflows may occur.
  • Be careful with negative values and the way they are visualized.
  • SUBTRACT The SUBTRACT arithmetic operator subtract a constant C from an image I. The formula applied between the input image $I$ and the operand $C$ is: $$O(n,m)=I(n,m)-C$$ Remarks:
  • Overflows may occur.
  • The result of a subtraction between a binary image and a constant 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 I by a constant C. The formula applied between the input image $I$ and the operand $C$ is: $$O(n,m)=I(n,m) \times C$$ Remarks:
  • Overflows may occur.
  • Be careful with negative values and the way they are visualized.
  • DIVIDE The DIVIDE arithmetic operator divides an image I by a constant C. The formula applied between the input image $I$ and the operand $C$ is: $$O(n,m)=I(n,m)\div C$$ Remarks:
  • Overflows may occur.
  • Be careful with negative values and the way they are visualized.
  • If $C=0$ then $O(n,m)=I(n,m)$
  • MINIMUM The MINIMUM arithmetic operator computes the minimum value between an image I and a constant C. The formula applied between the input image $I$ and the operand $C$ is: $$O(n,m)=\min\left\{I(n,m),C\right\}$$ For binary image, the MINIMUM operator is equivalent to a logical AND. $$ \begin{array}{|c|c|c|} \hline I_1 & C & I_1 \Lambda C\\ \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 an image I and a constant C. The formula applied between the input image $I$ and the operand $C$ is: $$O(n,m)=\max\left\{I(n,m),C\right\}$$ For binary image, the MAXIMUM operator is equivalent to a logical OR. $$ \begin{array}{|c|c|c|} \hline I_1 & C & I_1 \Delta C\\ \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 input. The output image type is deduced from the input.
    Image nullptr

    Object Examples

    std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );
    
    ArithmeticOperationWithValue arithmeticOperationWithValueAlgo;
    arithmeticOperationWithValueAlgo.setInputImage( polystyrene );
    arithmeticOperationWithValueAlgo.setValue( 10 );
    arithmeticOperationWithValueAlgo.setArithmeticOperator( ArithmeticOperationWithValue::ArithmeticOperator::ADD );
    arithmeticOperationWithValueAlgo.execute();
    
    std::cout << "outputImage:" << arithmeticOperationWithValueAlgo.outputImage()->toString();
    
    polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))
    
    arithmetic_operation_with_value_algo = imagedev.ArithmeticOperationWithValue()
    arithmetic_operation_with_value_algo.input_image = polystyrene
    arithmetic_operation_with_value_algo.value = 10
    arithmetic_operation_with_value_algo.arithmetic_operator = imagedev.ArithmeticOperationWithValue.ADD
    arithmetic_operation_with_value_algo.execute()
    
    print( "output_image:", str( arithmetic_operation_with_value_algo.output_image ) );
    
    ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );
    
    ArithmeticOperationWithValue arithmeticOperationWithValueAlgo = new ArithmeticOperationWithValue
    {
        inputImage = polystyrene,
        value = 10,
        arithmeticOperator = ArithmeticOperationWithValue.ArithmeticOperator.ADD
    };
    arithmeticOperationWithValueAlgo.Execute();
    
    Console.WriteLine( "outputImage:" + arithmeticOperationWithValueAlgo.outputImage.ToString() );
    

    Function Examples

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