You are here: Chapter 5: Verifying the Tested Application > Histogram Based Comparison

Histogram Based Comparison

The histogram based method (method "default") was historically the first algorithm provided with the tool. It was designed to compare two images of equal size (dimensions), typically full size screen shots of a desktop. The method is based on comparison of histograms (color counters) and merely tests whether two images of the same size contain the same number of pixels for each color (regardless of their position). It basically returns a percentage reflecting the rate of pixels of matching colors.
Histogram based comparison
Advantages of this method are simplicity (no template cropping is needed) and fast performance. If the desktop background is set to a solid color and number of objects on the desktop (such as icons) are kept to a minimum, histogram comparisons are also robustagainst location changes of application windows and produce the same result regardless of where the window appears on the screen.

Though this method was practically obsoleted by introduction of image search, it may be still successfully used for a quick test of large image changes against full desktop size templates. A typical example is a check point whether your application GUI displayed or not because a missing window produces a significant histogram comparison result drop.

The method may be also used for auto comparison supported by the Screenshot command. The point is that the command may be configured to search the template directory for images of the same name as the screen shot one and perform the comparison automatically is such a template is found even if image comparison is not enabled explicitly by the  parameters. This feature allows to reuse reviewed and approved screen shots saved from automated testing as templates for the next rounds of automation. To read more refer to the Screenshot command specification and look at the Preferences->Plugins->Script Commands->Screenshot Command window.

Commands employing histogram comparison compare the template(s) to the current desktop image and compare the result to the specified pass rate. If the rate is not specified on the command line, it defaults to 95% (it is configurable in Compareto preferences). The commands always return either 1 (meaning "the template does not match to the desktop with regard to the specified pass rate") or 0 (meaning "the template matches to the desktop with regard to the specified pass rate").

Created commands may be elaborated into scripts the same way as the image search one save that the method can not be used to locate a component on the screen. A typical usage is in form of "check point" to make sure that a larger update of the screen happened as expected, for example that a window of significant size got opened or disposed. The Waitfor match(or Waitfor mismatch) makes best sense:

Waitfor match template="desktop1.png" method="default" timeout=30s
if ({_EXIT_CODE} > 0) {
  Screenshot "failure.png" desc="The desktop doesn't seem to match to the desktop1.png
template!"
  Exit 1
}


The following short video shows how to employ histogram based comparison to make sure that the Calculator application displays correctly on the GNOME desktop:

Histogram based comparison applied to the calculator scriptHistogram based comparison applied to the calculator script
Histogram based comparison
applied to the calculator script
on Ubuntu Linux

 

12 December 2014

Copyright © T-Plan Ltd.

Version 1.0