Arithmetic and Logic Operations¶
This code snippet shows how to apply miscellaneous arithmetic and logic operations to images.
C++¶
#include <eVision/EasyImage/EasyImage.h>
using namespace eVision;
// Images constructor
EImageBW8 srcGray0, srcGray1, dstGray;
EImageC24 srcColor, dstColor;
// ...
// All images must have the same size
dstGray.SetSize(&srcGray0);
// ...
// Subtract srcGray1 from srcGray0
EasyImage::Oper(EArithmeticLogicOperation_Subtract, &srcGray0, &srcGray1, &dstGray);
// Multiply srcGray0 by a constant value
EasyImage::Oper(EArithmeticLogicOperation_Multiply, &srcGray0, EBW8(2), &dstGray);
// Add a constant value to srcColor
EasyImage::Oper(EArithmeticLogicOperation_Add, &srcColor, EC24(128, 64, 196), &dstColor);
// Erase (blacken) the destination image where the source image is black
EasyImage::Oper(EArithmeticLogicOperation_SetZero, &srcGray0, EBW8(0), &dstGray);
See also
C#¶
using eVision;
// Images constructor
EImageBW8 srcGray0 = new EImageBW8();
EImageBW8 srcGray1 = new EImageBW8();
EImageBW8 dstGray = new EImageBW8();
EImageC24 srcColor = new EImageC24();
EImageC24 dstColor = new EImageC24();
EBW8 bw8Constant = new EBW8(2);
EC24 c24Constant = new EC24(128, 64, 196);
// ...
// All images must have the same size
dstGray.SetSize(srcGray0);
dstColor.SetSize(srcColor);
// Subtract srcGray1 from srcGray0
EasyImage.Oper(EArithmeticLogicOperation.Subtract, srcGray0, srcGray1, dstGray);
// Multiply srcGray0 by a constant value
EasyImage.Oper(EArithmeticLogicOperation.Multiply, srcGray0, bw8Constant, dstGray);
// Add a constant value to srcColor
EasyImage.Oper(EArithmeticLogicOperation.Add, srcColor, c24Constant, dstColor);
// Erase (blacken) the destination image where the source image is black
bw8Constant.Value = (byte)0;
EasyImage.Oper(EArithmeticLogicOperation.SetZero, srcGray0, bw8Constant, dstGray);
See also
Python¶
import eVision
# Images constructor
srcGray0 = eVision.EImageBW8()
srcGray1 = eVision.EImageBW8()
dstGray = eVision.EImageBW8()
srcColor = eVision.EImageC24()
dstColor = eVision.EImageC24()
# ...
# All images must have the same size
dstGray.SetSize(srcGray0)
dstColor.SetSize(srcColor)
# ...
# Subtract srcGray1 from srcGray0
eVision.EasyImage.Oper(eVision.EArithmeticLogicOperation.Subtract, srcGray0, srcGray1, dstGray)
# Multiply srcGray0 by a constant value
eVision.EasyImage.Oper(eVision.EArithmeticLogicOperation.Multiply, srcGray0, eVision.EBW8(2), dstGray)
# Add a constant value to srcColor
eVision.EasyImage.Oper(eVision.EArithmeticLogicOperation.Add, srcColor, eVision.EC24(128, 64, 196), dstColor)
# Erase (blacken) the destination image where the source image is black
eVision.EasyImage.Oper(eVision.EArithmeticLogicOperation.SetZero, srcGray0, eVision.EBW8(0), dstGray)
See also