summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2016-02-17 10:25:53 +0000
committerJose Fonseca <jfonseca@vmware.com>2016-02-17 11:48:40 +0000
commit9b7da9c99599eee0f2811211a54ed4121c347442 (patch)
treea07c56c0f624f06af2c4fbb679ebcdbe5c0aa6a6 /scripts
parentf6305d3d105376de5306f6d0e70ff666df38d2e0 (diff)
scripts: Fix image diff highlighting.
Differences on certain channels were not being given enough weight when computing the alpha mask, so differences that were quite obvious to a human were not always being highlighted. The error was introduced by me several years ago when trying to mimic ImageMagick compare algorithm while mapping to the operations provided by Python PIL extension module, to avoid doing arithmetic in native Python, which would kill performance. But at least nowadays Python PIL/Pillow modules have lots of primitive operations that allow to get more accurate results without compromising performance, so it was relatively straightforward to fix this. Note we only mimic but never really tried to match exactly ImageMagick compare behavior. In particular, ImageMagic applies a step function when thresholding, when we do a linear ramp between 0 and the threshold, so that errors are not over the threshold get a proportional amount of red.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/snapdiff.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/scripts/snapdiff.py b/scripts/snapdiff.py
index 59ec870e..b0b7ed30 100755
--- a/scripts/snapdiff.py
+++ b/scripts/snapdiff.py
@@ -74,9 +74,17 @@ class Comparer:
if self.size_mismatch():
return
- # make a difference image similar to ImageMagick's compare utility
- mask = ImageEnhance.Brightness(self.diff).enhance(1.0/fuzz)
- mask = mask.convert('L')
+ # Make a difference image similar to ImageMagick's compare utility.
+ #
+ # Basically produces a brightened/faded version of the source image,
+ # but where every pixel for which absolute error is larger than
+ # 255*fuzz will be colored strong red.
+
+ # Take the maximum error across all channels
+ diff_max = reduce(ImageChops.lighter, self.diff.split())
+
+ # Scale values so that pixels equal or above 255*fuzz become 255
+ mask = diff_max.point(lambda x: min(x/fuzz, 255), 'L')
lowlight = Image.new('RGB', self.src_im.size, (0xff, 0xff, 0xff))
highlight = Image.new('RGB', self.src_im.size, (0xf1, 0x00, 0x1e))