ImageEn, unit imageenproc




function CompareWith(SecondImage: TIEBitmap; DiffBitmap: TIEBitmap = nil; CheckAlpha: Boolean = False; Coverage: Double = 1.0; CompareMethod: TIECompareMethod = iecwGrayScale): Double; overload;
function CompareWith(Rect: TRect; SecondImage: TIEBitmap; SecondImageRect: TRect; DiffBitmap: TIEBitmap = nil; Coverage: Double = 1.0; CompareMethod: TIECompareMethod = iecwGrayScale): Double; overload;


Compare the current image with SecondImage and returns a floating point value (0 to 1) specifying the percentage of equality. 1 means that two images are equal.
If CheckAlpha is False it does not take the alpha value of each pixel into account. If CheckAlpha is True it conisders the level of alpha to compare values. A fully transparent pixel will be treated the same as a white pixel.
The DiffBitmap can be nil, otherwise it will be receive a bitmap with the differences (PixelFormat will be converted to ie8g, if not ie8g or ie8p).
Coverage specifies the percentage of rows that are checked. This is used to speed up processing of very large images at the cost of accuracy. For example, 1.0 checks every row, 0.5 checks every second row, 0.1 every 10th row, 0.01 every 100th row, etc. Generally this options should not be used in combination with a DiffBitmap, because the resulting image will be incomplete.
The default Comparison Method is iecwGrayScale, which compares the intensity of the pixels, not the colors (i.e. grey scale and color versions of the same image will be considered identical). Alternatively you can specify iecwColorMetric which compares colors more similarly to the way humans do.

Second overload compares only the specified rectangle of the two images (the rects must be the same size).

 The images (or image rects if using the second overload) must be the same size (if they are different sizes any pixels outside the common area are ignored)
 It is best if the PixelFormat of both images is ie24RGB. If they are different formats, performance will be significantly degraded

Source Images


Result: 94.3% equal


Demo  Demos\ImageAnalysis\ImagesDiff\ImagesDiff.dpr
Demo  Demos\ImageEditing\EveryMethod\EveryMethod.dpr


Eq := ImageEnView1.Proc.CompareWith( ImageEnView2.IEBitmap, nil );

// Compare equality if image contains transparency
Eq := ImageEnView1.Proc.CompareWith( ImageEnView2.IEBitmap, nil, True );

// Compare and show difference in ImageEnView3
// Note: ImageEnView3 PixelFormat will be set to ie8g
Eq := ImageEnView1.Proc.CompareWith( ImageEnView2.IEBitmap, ImageEnView3.IEBitmap );

See Also