Arithmetic and Logic

Non-exhaustive list of reasons one may use arithmetic and logic operations:

  • To emphasize differences between images by subtracting the pixels (a conformity check).

  • To compensate for non-uniform lighting by dividing the target image by the image of the background alone.

  • To remove unwanted areas of an image by preparing an appropriate mask, and clearing all the pixels that belong to the mask by using logical combinations of pixels.

  • To create a combined image by combining the pixels of two source images to generate a resulting image.

Arithmetic operations are handled by the EasyImage::Oper .NET Python function, EArithmeticLogicOperation .NET Python enum lists all supported operators.

These operations can be applied to images and constants, they have one or two source arguments (image or integer constants) and one destination argument. If the source operands are a color and a gray-level image, each color component combines with the gray-level component to give a color image. Histogram equalization can improve your results.

Arithmetic and Logic Combinations

All possible operations are classed in seven categories in this documentation, and all operations for each category are detailed later.

Allowed Combinations of Input(s) and Output

Input(s)

Output

General

Copy

Invert

Shift

Logical

Overlay

Set

EBW8 constant

EImageBW8

✓

EC24 constant

EImageC24

✓

EImageBW8

EImageBW8

✓

✓

EImageBW8

EImageC24

✓

✓

✓

EImageC24

EImageC24

✓

✓

EBW8 constant and EImageBW8

EImageBW8

✓

EImageBW8 and EBW8 constant

EImageBW8

✓

✓

✓

EImageBW8 and EImageBW8

EImageBW8

✓

✓

✓

EImageBW8 and EImageBW8

EImageC24

✓

✓

EC24 constant and EImageC24

EImageC24

✓

EImageC24 and EC24 constant

EImageC24

✓

✓

EImageC24 and EImageC24

EImageC24

✓

✓

EImageC24 and EImageBW8

EImageC24

✓

✓

✓

EImageBW8 and EImageC24

EImageC24

✓

✓

✓

Note

For logical operators, a pixel with value 0 is assumed false, otherwise true. The result of a logical operation is 0 when false and 255 when true.

General Operations

  • Compare (abs. value of the difference)

  • Saturated sum

  • Saturated difference

  • Saturated product

  • Saturated quotient

  • Modulo

  • Overflow-free sum

  • Overflow-free difference

  • Overflow-free product

  • Overflow-free quotient

  • Bitwise AND

  • Bitwise OR

  • Bitwise XOR

  • Minimum

  • Maximum

  • Equal

  • Not equal

  • Greater or equal

  • Lesser or equal

  • Greater

  • Lesser

Copy Operations

Invert Operations

  • Invert EArithmeticLogicOperation_Invert .NET Python

    • When not specifying a constant, the image is inverted into the destination image. Which means, each pixel channel value is computed as \(255 - pixelChannelValue\)

    • Otherwise, when a constant is specified, it is computed as \(constant - pixelChannelValue\)

Shift Operations

Logical Operations

Overlay Operations

Set Operations

This operation involves three images.

  • Source Image: that will be conditionally copied to Destination Image.

  • Mask Image: that will set whether a pixel from Source Image must be copied to Destination Image.

  • Destination Image: whose pixels will equal pixel from Source Image if mask image pixel is

EasyImage::Oper(EArithmeticLogicOperation_SetZero, &sourceImage, &maskImage, &destinationImage);
EasyImage.Oper(EArithmeticLogicOperation.SetZero, sourceImage, maskImage, destinationImage);
EasyImage.Oper(EArithmeticLogicOperation.SetZero, sourceImage, maskImage, destinationImage);

Note

For logical operators, a pixel with value 0 is assumed false, otherwise true. The result of a logical operation is 0 when false and 255 when true.

See Also

Code Snippets

Easy to understand, ready to copy code snippets.

Arithmetic and Logic Operations