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 |
|---|---|---|---|---|---|---|---|---|
|
|
✓ |
||||||
|
|
✓ |
||||||
|
|
✓ |
✓ |
|||||
|
|
✓ |
✓ |
✓ |
||||
|
|
✓ |
✓ |
|||||
|
|
✓ |
||||||
|
|
✓ |
✓ |
✓ |
||||
|
|
✓ |
✓ |
✓ |
||||
|
|
✓ |
✓ |
|||||
|
|
✓ |
||||||
|
|
✓ |
✓ |
|||||
|
|
✓ |
✓ |
|||||
|
|
✓ |
✓ |
✓ |
||||
|
|
✓ |
✓ |
✓ |
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¶
|
|
Copy Operations¶
Copy
EArithmeticLogicOperation_Copy.NET PythonCopies a constant to all the pixels of an image. Useful, for example, to initialize a newly created image.
Copies an image to another image.
Invert Operations¶
Invert
EArithmeticLogicOperation_Invert.NET PythonWhen 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¶
Left Shift
EArithmeticLogicOperation_ShiftLeft.NET PythonRight Shift
EArithmeticLogicOperation_ShiftRight.NET Python
Logical Operations¶
Logical AND
EArithmeticLogicOperation_LogicalAnd.NET PythonLogical OR
EArithmeticLogicOperation_LogicalOr.NET PythonLogical XOR
EArithmeticLogicOperation_LogicalXor.NET Python
Overlay Operations¶
Add an overlay
EArithmeticLogicOperation_Overlay.NET Python
Set Operations¶
This operation involves three images.
Source Image: that will be conditionally copied toDestination Image.Mask Image: that will set whether a pixel fromSource Imagemust be copied toDestination Image.Destination Image: whose pixels will equal pixel fromSource Imageif mask image pixel isEqual to zero when using
EArithmeticLogicOperation_SetZero.NET PythonDifferent from zero when using
EArithmeticLogicOperation_SetNonZero.NET PythonOtherwise, the pixel value is unchanged.
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¶
Easy to understand, ready to copy code snippets.