Algorithm allowing to compare two images.
This algorithm allows to compare two images. Images must have same size and buffer type for comparison.
Through the input parameter InOptImgComparisonTolerance::ToleranceType, the user can choose among several tolerance policies:
- eImgComparisonToleranceType::eICTT_NoTolerance: comparison succeeds if and only if the 2 input images are rigorously identical
- eImgComparisonToleranceType::eICTT_Absolute: comparison succeeds if and only if, for each pair of pixels (in1, in2) at the same position in the 2 input images:

- eImgComparisonToleranceType::eICTT_Relative: comparison succeeds if and only if, for each pair of pixels (in1, in2) at the same position in the 2 input images:

- eImgComparisonToleranceType::eICTT_AbsoluteOrRelative: comparison succeeds if and only if, for each pair of pixels (in1, in2) at the same position in the 2 input images, at least one of the 2 following conditions is satisfied:


The result of the comparison is a data item containing the following attributes:
- BEqual: boolean, initialized to true if the comparison succeeded, to false otherwise
- NbDiff: integer, containing the number of pixels out of tolerance
- PixCount: integer, containing the number of pixels in each image
- OutOfPixPosition: data-item, containing the coordinates of the first pixel found (if exists), that is out-of-tolerance
- OutOfTolPix1Value: value of the first pixel found (if exists) in the first input image, that is out-of-tolerance
- OutOfTolPix2Value: value of the first pixel found (if exists) in the second input image, that is out-of-tolerance
On output a CompareResult structure is filled.
Example of Python code :
Example imports
import PyIPSDK
import PyIPSDK.IPSDKIPLUtility as util
Code Example
inputGeometry = PyIPSDK.geometry2d(PyIPSDK.eImageBufferType.eIBT_UInt8, 510, 509)
image1 = PyIPSDK.loadRawImageFile(inputImgPath1, inputGeometry)
image2 = PyIPSDK.loadRawImageFile(inputImgPath2, inputGeometry)
compareResult = util.compareImg(image1, image2)
bEqual = compareResult.bEqual
nbDiff = compareResult.nbDiff
pixCount = compareResult.pixCount
Example of C++ code :
Example informations
Header file
#include <IPSDKIPL/IPSDKIPLUtility/Processor/CompareImg/CompareImg.h>
Code Example
const bool bEqual = pCompareResult->getValue<CompareResult::BEqual>();
const ipUInt64 nbDiff = pCompareResult->getValue<CompareResult::NbDiff>();
const ipUInt64 pixCount = pCompareResult->getValue<CompareResult::PixCount>();