summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcgrimm@chromium.org <cgrimm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-05 21:16:12 +0000
committercgrimm@chromium.org <cgrimm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-05 21:16:12 +0000
commit08d600aafb6b6c673712bfd1df7e31920aed6605 (patch)
tree1c54a77a5d98799e42c202c454bbcb24632469a7
parent177dcee207de2f248bc66cfaa99ab91a9d8e7c12 (diff)
downloadchromium_src-08d600aafb6b6c673712bfd1df7e31920aed6605.zip
chromium_src-08d600aafb6b6c673712bfd1df7e31920aed6605.tar.gz
chromium_src-08d600aafb6b6c673712bfd1df7e31920aed6605.tar.bz2
[i-spy] moved image_tools and corresponding tests into the new directory structure.
BUG= moved image_tools and tests into directory structure. Review URL: https://chromiumcodereview.appspot.com/18399002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215679 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/test/functional/ispy/image_tools_test.py189
-rw-r--r--chrome/test/functional/ispy/ispy_core/tools/image_tools.py (renamed from chrome/test/functional/ispy/image_tools.py)105
-rw-r--r--chrome/test/functional/ispy/ispy_core/tools/image_tools_unittest.py217
3 files changed, 308 insertions, 203 deletions
diff --git a/chrome/test/functional/ispy/image_tools_test.py b/chrome/test/functional/ispy/image_tools_test.py
deleted file mode 100644
index 4ae5793..0000000
--- a/chrome/test/functional/ispy/image_tools_test.py
+++ /dev/null
@@ -1,189 +0,0 @@
-# Copyright 2013 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import unittest
-from PIL import Image
-
-import image_tools
-
-
-def _GenImage(size, color):
- return Image.new('RGB', size, color)
-
-
-def _AllPixelsOfColor(image, color):
- return not any(px != color for px in image.getdata())
-
-
-class ImageToolsTest(unittest.TestCase):
-
- def testAreTheSameSize(self):
- black25x25 = _GenImage((25, 25), (0, 0, 0))
- white25x25 = _GenImage((25, 25), (255, 255, 255))
- black50x50 = _GenImage((50, 50), (0, 0, 0))
- white50x50 = _GenImage((50, 50), (255, 255, 255))
-
- self.assertTrue(image_tools._AreTheSameSize([black25x25, black25x25]))
- self.assertTrue(image_tools._AreTheSameSize([white25x25, white25x25]))
- self.assertTrue(image_tools._AreTheSameSize([black50x50, black50x50]))
- self.assertTrue(image_tools._AreTheSameSize([white50x50, white50x50]))
- self.assertTrue(image_tools._AreTheSameSize([black25x25, white25x25]))
- self.assertTrue(image_tools._AreTheSameSize([black50x50, white50x50]))
-
- self.assertFalse(image_tools._AreTheSameSize([black50x50, black25x25]))
- self.assertFalse(image_tools._AreTheSameSize([white50x50, white25x25]))
- self.assertFalse(image_tools._AreTheSameSize([black25x25, white50x50]))
- self.assertFalse(image_tools._AreTheSameSize([black50x50, white25x25]))
-
- self.assertRaises(Exception, image_tools._AreTheSameSize, [])
- self.assertRaises(Exception, image_tools._AreTheSameSize, [black50x50])
-
- def testGetDifferenceWithMask(self):
- black25x25 = _GenImage((25, 25), (0, 0, 0))
- white25x25 = _GenImage((25, 25), (255, 255, 255))
- black50x50 = _GenImage((50, 50), (0, 0, 0))
- self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
- black25x25, black25x25), (0, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
- white25x25, white25x25), (0, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
- white25x25, black25x25), (255, 255, 255)))
- self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
- black25x25, black25x25, mask=black25x25), (0, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
- black25x25, black25x25, mask=white25x25), (0, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
- black25x25, white25x25, mask=black25x25), (255, 255, 255)))
- self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
- black25x25, white25x25, mask=white25x25), (0, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
- black25x25, white25x25, different_color=(255, 0, 0)), (255, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
- white25x25, white25x25, same_color=(255, 0, 0)), (255, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
- white25x25, white25x25,
- mask=white25x25, masked_color=(255, 0, 0)), (255, 0, 0)))
- self.assertRaises(Exception, image_tools._GetDifferenceWithMask,
- white25x25,
- black50x50)
- self.assertRaises(Exception, image_tools._GetDifferenceWithMask,
- white25x25,
- white25x25,
- mask=black50x50)
-
- def testCreateMask(self):
- black25x25 = _GenImage((25, 25), (0, 0, 0))
- white25x25 = _GenImage((25, 25), (255, 255, 255))
-
- m1 = image_tools.CreateMask([black25x25, white25x25])
- self.assertTrue(_AllPixelsOfColor(m1, (255, 255, 255)))
- m2 = image_tools.CreateMask([black25x25, black25x25])
- self.assertTrue(_AllPixelsOfColor(m2, (0, 0, 0)))
- m3 = image_tools.CreateMask([white25x25, white25x25])
- self.assertTrue(_AllPixelsOfColor(m3, (0, 0, 0)))
-
- def testTotalDifferentPixels(self):
- white25x25 = _GenImage((25, 25), (255, 255, 255))
- white50x50 = _GenImage((50, 50), (255, 255, 255))
- black25x25 = _GenImage((25, 25), (0, 0, 0))
-
- self.assertEquals(image_tools.TotalDifferentPixels(white25x25,
- white25x25),
- 0)
- self.assertEquals(image_tools.TotalDifferentPixels(black25x25,
- black25x25),
- 0)
- self.assertEquals(image_tools.TotalDifferentPixels(white25x25,
- black25x25),
- 25*25)
- self.assertEquals(image_tools.TotalDifferentPixels(white25x25,
- black25x25,
- mask=white25x25),
- 0)
- self.assertEquals(image_tools.TotalDifferentPixels(white25x25,
- white25x25,
- mask=white25x25),
- 0)
- self.assertEquals(image_tools.TotalDifferentPixels(white25x25,
- black25x25,
- mask=black25x25),
- 25*25)
- self.assertEquals(image_tools.TotalDifferentPixels(white25x25,
- white25x25,
- mask=black25x25),
- 0)
- self.assertRaises(Exception, image_tools.TotalDifferentPixels,
- white25x25, white50x50)
- self.assertRaises(Exception, image_tools.TotalDifferentPixels,
- white25x25, white25x25, mask=white50x50)
-
- def testSameImage(self):
- white25x25 = _GenImage((25, 25), (255, 255, 255))
- black25x25 = _GenImage((25, 25), (0, 0, 0))
- white50x50 = _GenImage((50, 50), (255, 255, 255))
-
- self.assertTrue(image_tools.SameImage(white25x25, white25x25))
- self.assertFalse(image_tools.SameImage(white25x25, black25x25))
-
- self.assertTrue(image_tools.SameImage(white25x25, black25x25,
- mask=white25x25))
- self.assertFalse(image_tools.SameImage(white25x25, black25x25,
- mask=black25x25))
- self.assertTrue(image_tools.SameImage(black25x25, black25x25))
- self.assertTrue(image_tools.SameImage(black25x25, black25x25,
- mask=white25x25))
- self.assertTrue(image_tools.SameImage(white25x25, white25x25,
- mask=white25x25))
- self.assertRaises(Exception, image_tools.SameImage,
- white25x25, white50x50)
- self.assertRaises(Exception, image_tools.SameImage,
- white25x25, white25x25,
- mask=white50x50)
-
- def testVisualizeImageDifferences(self):
- white25x25 = _GenImage((25, 25), (255, 255, 255))
- black25x25 = _GenImage((25, 25), (0, 0, 0))
- white50x50 = _GenImage((50, 50), (255, 255, 255))
- self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
- white25x25, black25x25), (255, 255, 255)))
- self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
- white25x25, white25x25), (0, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
- black25x25, black25x25), (0, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
- white25x25, black25x25, mask=white25x25), (0, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
- white25x25, black25x25, mask=black25x25), (255, 255, 255)))
- self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
- white25x25, white25x25, mask=white25x25), (0, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
- white25x25, white25x25, mask=black25x25), (0, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
- black25x25, black25x25, mask=black25x25), (0, 0, 0)))
- self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
- black25x25, black25x25, mask=white25x25), (0, 0, 0)))
-
- self.assertRaises(Exception,
- image_tools.VisualizeImageDifferences,
- white25x25,
- white50x50)
- self.assertRaises(Exception,
- image_tools.VisualizeImageDifferences,
- white25x25,
- black25x25,
- mask=white50x50)
-
- def testSerialization(self):
- black25x25 = _GenImage((25, 25), (0, 0, 0))
- white25x25 = _GenImage((25, 25), (255, 255, 255))
- self.assertTrue(_AllPixelsOfColor(
- image_tools.DeserializeImage(
- image_tools.SerializeImage(white25x25)), (255, 255, 255)))
- self.assertTrue(_AllPixelsOfColor(
- image_tools.DeserializeImage(
- image_tools.SerializeImage(black25x25)), (0, 0, 0)))
-
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/chrome/test/functional/ispy/image_tools.py b/chrome/test/functional/ispy/ispy_core/tools/image_tools.py
index bf0402a..e87dbe8 100644
--- a/chrome/test/functional/ispy/image_tools.py
+++ b/chrome/test/functional/ispy/ispy_core/tools/image_tools.py
@@ -6,7 +6,6 @@
import itertools
import StringIO
-import PIL
from PIL import Image
@@ -29,9 +28,9 @@ def _AreTheSameSize(images):
def _GetDifferenceWithMask(image1, image2, mask=None,
- masked_color=(0, 0, 0),
- same_color=(0, 0, 0),
- different_color=(255, 255, 255)):
+ masked_color=(0, 0, 0, 255),
+ same_color=(0, 0, 0, 255),
+ different_color=(255, 255, 255, 255)):
"""Returns an image representing the difference between the two images.
This function computes the difference between two images taking into
@@ -57,15 +56,15 @@ def _GetDifferenceWithMask(image1, image2, mask=None,
"""
image_mask = mask
if not mask:
- image_mask = PIL.Image.new('RGB', image1.size, (0, 0, 0))
+ image_mask = Image.new('RGBA', image1.size, (0, 0, 0, 255))
if not _AreTheSameSize([image1, image2, image_mask]):
raise Exception('images and mask must be the same size.')
- image_diff = PIL.Image.new('RGB', image1.size, (0, 0, 0))
+ image_diff = Image.new('RGBA', image1.size, (0, 0, 0, 255))
data = []
for m, px1, px2 in itertools.izip(image_mask.getdata(),
image1.getdata(),
image2.getdata()):
- if m == (255, 255, 255):
+ if m == (255, 255, 255, 255):
data.append(masked_color)
elif px1 == px2:
data.append(same_color)
@@ -97,17 +96,43 @@ def CreateMask(images):
"""
if len(images) < 2:
raise Exception('mask must be created from two or more images.')
- mask = Image.new('RGB', images[0].size, (0, 0, 0))
+ mask = Image.new('RGBA', images[0].size, (0, 0, 0, 255))
image = images[0]
for other_image in images[1:]:
mask = _GetDifferenceWithMask(
image,
other_image,
mask,
- masked_color=(255, 255, 255))
+ masked_color=(255, 255, 255, 255))
return mask
+def AddMasks(masks):
+ """Combines a list of mask images into one mask image.
+
+ Args:
+ masks: a list of mask-images.
+
+ Returns:
+ a new mask that represents the sum of the masked
+ regions of the passed in list of mask-images.
+
+ Raises:
+ Exception: if masks is an empty list, or if masks are not the same size.
+ """
+ if not masks:
+ raise Exception('masks must be a list containing at least one image.')
+ if len(masks) > 1 and not _AreTheSameSize(masks):
+ raise Exception('masks in list must be of the same size.')
+ white = (255, 255, 255, 255)
+ black = (0, 0, 0, 255)
+ masks_data = [mask.getdata() for mask in masks]
+ image = Image.new('RGBA', masks[0].size, black)
+ image.putdata([white if white in px_set else black
+ for px_set in itertools.izip(*masks_data)])
+ return image
+
+
def VisualizeImageDifferences(image1, image2, mask=None):
"""Returns an image repesenting the unmasked differences between two images.
@@ -134,6 +159,60 @@ def VisualizeImageDifferences(image1, image2, mask=None):
return _GetDifferenceWithMask(image1, image2, mask)
+def InflateMask(image, passes):
+ """A function that adds layers of pixels around the white edges of a mask.
+
+ This function evaluates a 'frontier' of valid pixels indices. Initially,
+ this frontier contains all indices in the image. However, with each pass
+ only the pixels' indices which were added to the mask by inflation
+ are added to the next pass's frontier. This gives the algorithm a
+ large upfront cost that scales negligably when the number of passes
+ is increased.
+
+ Args:
+ image: the RGBA PIL.Image mask to inflate.
+ passes: the number of passes to inflate the image by.
+
+ Returns:
+ A RGBA PIL.Image.
+ """
+ inflated = Image.new('RGBA', image.size)
+ new_dataset = list(image.getdata())
+ old_dataset = list(image.getdata())
+
+ frontier = set(range(len(old_dataset)))
+ new_frontier = set()
+
+ l = [-1, 1]
+
+ def _ShadeHorizontal(index, px):
+ col = index % image.size[0]
+ if px == (255, 255, 255, 255):
+ for x in l:
+ if 0 <= col + x < image.size[0]:
+ if old_dataset[index + x] != (255, 255, 255, 255):
+ new_frontier.add(index + x)
+ new_dataset[index + x] = (255, 255, 255, 255)
+
+ def _ShadeVertical(index, px):
+ row = index / image.size[0]
+ if px == (255, 255, 255, 255):
+ for x in l:
+ if 0 <= row + x < image.size[1]:
+ if old_dataset[index + image.size[0] * x] != (255, 255, 255, 255):
+ new_frontier.add(index + image.size[0] * x)
+ new_dataset[index + image.size[0] * x] = (255, 255, 255, 255)
+
+ for _ in range(passes):
+ for index in frontier:
+ _ShadeHorizontal(index, old_dataset[index])
+ _ShadeVertical(index, old_dataset[index])
+ old_dataset, new_dataset = new_dataset, new_dataset
+ frontier, new_frontier = new_frontier, set()
+ inflated.putdata(new_dataset)
+ return inflated
+
+
def TotalDifferentPixels(image1, image2, mask=None):
"""Computes the number of different pixels between two images.
@@ -151,13 +230,13 @@ def TotalDifferentPixels(image1, image2, mask=None):
"""
image_mask = mask
if not mask:
- image_mask = PIL.Image.new('RGB', image1.size, (0, 0, 0))
+ image_mask = Image.new('RGBA', image1.size, (0, 0, 0, 255))
if _AreTheSameSize([image1, image2, image_mask]):
total_diff = 0
for px1, px2, m in itertools.izip(image1.getdata(),
image2.getdata(),
image_mask.getdata()):
- if m == (255, 255, 255):
+ if m == (255, 255, 255, 255):
continue
elif px1 != px2:
total_diff += 1
@@ -217,6 +296,4 @@ def DeserializeImage(encoded_image):
Returns:
an RGB image
"""
- return PIL.Image.open(StringIO.StringIO(encoded_image.decode('base64')))
-
-
+ return Image.open(StringIO.StringIO(encoded_image.decode('base64')))
diff --git a/chrome/test/functional/ispy/ispy_core/tools/image_tools_unittest.py b/chrome/test/functional/ispy/ispy_core/tools/image_tools_unittest.py
new file mode 100644
index 0000000..46f3702
--- /dev/null
+++ b/chrome/test/functional/ispy/ispy_core/tools/image_tools_unittest.py
@@ -0,0 +1,217 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import unittest
+from PIL import Image
+import image_tools
+
+
+def _GenImage(size, color):
+ return Image.new('RGBA', size, color)
+
+
+def _AllPixelsOfColor(image, color):
+ return not any(px != color for px in image.getdata())
+
+
+class ImageToolsTest(unittest.TestCase):
+
+ def setUp(self):
+ self.black25 = _GenImage((25, 25), (0, 0, 0, 255))
+ self.black50 = _GenImage((50, 50), (0, 0, 0, 255))
+ self.white25 = _GenImage((25, 25), (255, 255, 255, 255))
+ self.white50 = _GenImage((50, 50), (255, 255, 255, 255))
+
+ def testAreTheSameSize(self):
+ self.assertTrue(image_tools._AreTheSameSize([self.black25, self.black25]))
+ self.assertTrue(image_tools._AreTheSameSize([self.white25, self.white25]))
+ self.assertTrue(image_tools._AreTheSameSize([self.black50, self.black50]))
+ self.assertTrue(image_tools._AreTheSameSize([self.white50, self.white50]))
+ self.assertTrue(image_tools._AreTheSameSize([self.black25, self.white25]))
+ self.assertTrue(image_tools._AreTheSameSize([self.black50, self.white50]))
+
+ self.assertFalse(image_tools._AreTheSameSize([self.black50, self.black25]))
+ self.assertFalse(image_tools._AreTheSameSize([self.white50, self.white25]))
+ self.assertFalse(image_tools._AreTheSameSize([self.black25, self.white50]))
+ self.assertFalse(image_tools._AreTheSameSize([self.black50, self.white25]))
+
+ self.assertRaises(Exception, image_tools._AreTheSameSize, [])
+ self.assertRaises(Exception, image_tools._AreTheSameSize, [self.black50])
+
+ def testGetDifferenceWithMask(self):
+ self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
+ self.black25, self.black25), (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
+ self.white25, self.white25), (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
+ self.white25, self.black25), (255, 255, 255, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
+ self.black25, self.black25, mask=self.black25), (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
+ self.black25, self.black25, mask=self.white25), (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
+ self.black25, self.white25, mask=self.black25), (255, 255, 255, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
+ self.black25, self.white25, mask=self.white25), (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
+ self.black25, self.white25, different_color=(255, 0, 0, 255)),
+ (255, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
+ self.white25, self.white25, same_color=(255, 0, 0, 255)),
+ (255, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools._GetDifferenceWithMask(
+ self.white25, self.white25,
+ mask=self.white25, masked_color=(255, 0, 0, 255)), (255, 0, 0, 255)))
+ self.assertRaises(Exception, image_tools._GetDifferenceWithMask,
+ self.white25,
+ self.black50)
+ self.assertRaises(Exception, image_tools._GetDifferenceWithMask,
+ self.white25,
+ self.white25,
+ mask=self.black50)
+
+ def testCreateMask(self):
+ m1 = image_tools.CreateMask([self.black25, self.white25])
+ self.assertTrue(_AllPixelsOfColor(m1, (255, 255, 255, 255)))
+ m2 = image_tools.CreateMask([self.black25, self.black25])
+ self.assertTrue(_AllPixelsOfColor(m2, (0, 0, 0, 255)))
+ m3 = image_tools.CreateMask([self.white25, self.white25])
+ self.assertTrue(_AllPixelsOfColor(m3, (0, 0, 0, 255)))
+
+ def testAddMasks(self):
+ m1 = image_tools.CreateMask([self.black25, self.white25])
+ m2 = image_tools.CreateMask([self.black25, self.black25])
+ m3 = image_tools.CreateMask([self.black50, self.black50])
+ self.assertTrue(_AllPixelsOfColor(image_tools.AddMasks([m1]),
+ (255, 255, 255, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.AddMasks([m2]),
+ (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.AddMasks([m1, m2]),
+ (255, 255, 255, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.AddMasks([m1, m1]),
+ (255, 255, 255, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.AddMasks([m2, m2]),
+ (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.AddMasks([m3]),
+ (0, 0, 0, 255)))
+ self.assertRaises(Exception, image_tools.AddMasks, [])
+ self.assertRaises(Exception, image_tools.AddMasks, [m1, m3])
+
+ def testTotalDifferentPixels(self):
+ self.assertEquals(image_tools.TotalDifferentPixels(self.white25,
+ self.white25),
+ 0)
+ self.assertEquals(image_tools.TotalDifferentPixels(self.black25,
+ self.black25),
+ 0)
+ self.assertEquals(image_tools.TotalDifferentPixels(self.white25,
+ self.black25),
+ 25*25)
+ self.assertEquals(image_tools.TotalDifferentPixels(self.white25,
+ self.black25,
+ mask=self.white25),
+ 0)
+ self.assertEquals(image_tools.TotalDifferentPixels(self.white25,
+ self.white25,
+ mask=self.white25),
+ 0)
+ self.assertEquals(image_tools.TotalDifferentPixels(self.white25,
+ self.black25,
+ mask=self.black25),
+ 25*25)
+ self.assertEquals(image_tools.TotalDifferentPixels(self.white25,
+ self.white25,
+ mask=self.black25),
+ 0)
+ self.assertRaises(Exception, image_tools.TotalDifferentPixels,
+ self.white25, self.white50)
+ self.assertRaises(Exception, image_tools.TotalDifferentPixels,
+ self.white25, self.white25, mask=self.white50)
+
+ def testSameImage(self):
+ self.assertTrue(image_tools.SameImage(self.white25, self.white25))
+ self.assertFalse(image_tools.SameImage(self.white25, self.black25))
+
+ self.assertTrue(image_tools.SameImage(self.white25, self.black25,
+ mask=self.white25))
+ self.assertFalse(image_tools.SameImage(self.white25, self.black25,
+ mask=self.black25))
+ self.assertTrue(image_tools.SameImage(self.black25, self.black25))
+ self.assertTrue(image_tools.SameImage(self.black25, self.black25,
+ mask=self.white25))
+ self.assertTrue(image_tools.SameImage(self.white25, self.white25,
+ mask=self.white25))
+ self.assertRaises(Exception, image_tools.SameImage,
+ self.white25, self.white50)
+ self.assertRaises(Exception, image_tools.SameImage,
+ self.white25, self.white25,
+ mask=self.white50)
+
+ def testInflateMask(self):
+ cross_image = Image.new('RGBA', (3, 3))
+ white_image = Image.new('RGBA', (3, 3))
+ dot_image = Image.new('RGBA', (3, 3))
+ b = (0, 0, 0, 255)
+ w = (255, 255, 255, 255)
+ dot_image.putdata([b, b, b,
+ b, w, b,
+ b, b, b])
+ cross_image.putdata([b, w, b,
+ w, w, w,
+ b, w, b])
+ white_image.putdata([w, w, w,
+ w, w, w,
+ w, w, w])
+ self.assertEquals(list(image_tools.InflateMask(dot_image, 1).getdata()),
+ list(cross_image.getdata()))
+ self.assertEquals(list(image_tools.InflateMask(dot_image, 0).getdata()),
+ list(dot_image.getdata()))
+ self.assertEquals(list(image_tools.InflateMask(dot_image, 2).getdata()),
+ list(white_image.getdata()))
+ self.assertEquals(list(image_tools.InflateMask(dot_image, 3).getdata()),
+ list(white_image.getdata()))
+ self.assertEquals(list(image_tools.InflateMask(self.black25, 1).getdata()),
+ list(self.black25.getdata()))
+
+ def testVisualizeImageDifferences(self):
+ self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
+ self.white25, self.black25), (255, 255, 255, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
+ self.white25, self.white25), (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
+ self.black25, self.black25), (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
+ self.white25, self.black25, mask=self.white25), (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
+ self.white25, self.black25, mask=self.black25), (255, 255, 255, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
+ self.white25, self.white25, mask=self.white25), (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
+ self.white25, self.white25, mask=self.black25), (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
+ self.black25, self.black25, mask=self.black25), (0, 0, 0, 255)))
+ self.assertTrue(_AllPixelsOfColor(image_tools.VisualizeImageDifferences(
+ self.black25, self.black25, mask=self.white25), (0, 0, 0, 255)))
+
+ self.assertRaises(Exception,
+ image_tools.VisualizeImageDifferences,
+ self.white25,
+ self.white50)
+ self.assertRaises(Exception,
+ image_tools.VisualizeImageDifferences,
+ self.white25,
+ self.black25,
+ mask=self.white50)
+
+ def testSerialization(self):
+ self.assertTrue(_AllPixelsOfColor(
+ image_tools.DeserializeImage(
+ image_tools.SerializeImage(self.white25)), (255, 255, 255, 255)))
+ self.assertTrue(_AllPixelsOfColor(
+ image_tools.DeserializeImage(
+ image_tools.SerializeImage(self.black25)), (0, 0, 0, 255)))
+
+
+if __name__ == '__main__':
+ unittest.main()