| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 """ | 3 """ |
| 4 Copyright 2013 Google Inc. | 4 Copyright 2013 Google Inc. |
| 5 | 5 |
| 6 Use of this source code is governed by a BSD-style license that can be | 6 Use of this source code is governed by a BSD-style license that can be |
| 7 found in the LICENSE file. | 7 found in the LICENSE file. |
| 8 | 8 |
| 9 Calulate differences between image pairs, and store them in a database. | 9 Calulate differences between image pairs, and store them in a database. |
| 10 """ | 10 """ |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 DISALLOWED_FILEPATH_CHAR_REGEX = re.compile('[^\w\-]') | 39 DISALLOWED_FILEPATH_CHAR_REGEX = re.compile('[^\w\-]') |
| 40 | 40 |
| 41 DIFFS_SUBDIR = 'diffs' | 41 DIFFS_SUBDIR = 'diffs' |
| 42 WHITEDIFFS_SUBDIR = 'whitediffs' | 42 WHITEDIFFS_SUBDIR = 'whitediffs' |
| 43 | 43 |
| 44 VALUES_PER_BAND = 256 | 44 VALUES_PER_BAND = 256 |
| 45 | 45 |
| 46 # Keys used within DiffRecord dictionary representations. | 46 # Keys used within DiffRecord dictionary representations. |
| 47 # NOTE: Keep these in sync with static/constants.js | 47 # NOTE: Keep these in sync with static/constants.js |
| 48 KEY__DIFFERENCE_DATA__MAX_DIFF_PER_CHANNEL = 'maxDiffPerChannel' | 48 KEY__DIFFERENCES__MAX_DIFF_PER_CHANNEL = 'maxDiffPerChannel' |
| 49 KEY__DIFFERENCE_DATA__NUM_DIFF_PIXELS = 'numDifferingPixels' | 49 KEY__DIFFERENCES__NUM_DIFF_PIXELS = 'numDifferingPixels' |
| 50 KEY__DIFFERENCE_DATA__PERCENT_DIFF_PIXELS = 'percentDifferingPixels' | 50 KEY__DIFFERENCES__PERCENT_DIFF_PIXELS = 'percentDifferingPixels' |
| 51 KEY__DIFFERENCE_DATA__PERCEPTUAL_DIFF = 'perceptualDifference' | 51 KEY__DIFFERENCES__PERCEPTUAL_DIFF = 'perceptualDifference' |
| 52 KEY__DIFFERENCE_DATA__WEIGHTED_DIFF = 'weightedDiffMeasure' | 52 KEY__DIFFERENCES__WEIGHTED_DIFF = 'weightedDiffMeasure' |
| 53 | 53 |
| 54 | 54 |
| 55 class DiffRecord(object): | 55 class DiffRecord(object): |
| 56 """ Record of differences between two images. """ | 56 """ Record of differences between two images. """ |
| 57 | 57 |
| 58 def __init__(self, storage_root, | 58 def __init__(self, storage_root, |
| 59 expected_image_url, expected_image_locator, | 59 expected_image_url, expected_image_locator, |
| 60 actual_image_url, actual_image_locator, | 60 actual_image_url, actual_image_locator, |
| 61 expected_images_subdir=DEFAULT_IMAGES_SUBDIR, | 61 expected_images_subdir=DEFAULT_IMAGES_SUBDIR, |
| 62 actual_images_subdir=DEFAULT_IMAGES_SUBDIR, | 62 actual_images_subdir=DEFAULT_IMAGES_SUBDIR, |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 199 |
| 200 def get_max_diff_per_channel(self): | 200 def get_max_diff_per_channel(self): |
| 201 """Returns the maximum difference between the expected and actual images | 201 """Returns the maximum difference between the expected and actual images |
| 202 for each R/G/B channel, as a list.""" | 202 for each R/G/B channel, as a list.""" |
| 203 return self._max_diff_per_channel | 203 return self._max_diff_per_channel |
| 204 | 204 |
| 205 def as_dict(self): | 205 def as_dict(self): |
| 206 """Returns a dictionary representation of this DiffRecord, as needed when | 206 """Returns a dictionary representation of this DiffRecord, as needed when |
| 207 constructing the JSON representation.""" | 207 constructing the JSON representation.""" |
| 208 return { | 208 return { |
| 209 KEY__DIFFERENCE_DATA__NUM_DIFF_PIXELS: self._num_pixels_differing, | 209 KEY__DIFFERENCES__NUM_DIFF_PIXELS: self._num_pixels_differing, |
| 210 KEY__DIFFERENCE_DATA__PERCENT_DIFF_PIXELS: | 210 KEY__DIFFERENCES__PERCENT_DIFF_PIXELS: |
| 211 self.get_percent_pixels_differing(), | 211 self.get_percent_pixels_differing(), |
| 212 KEY__DIFFERENCE_DATA__WEIGHTED_DIFF: self.get_weighted_diff_measure(), | 212 KEY__DIFFERENCES__WEIGHTED_DIFF: self.get_weighted_diff_measure(), |
| 213 KEY__DIFFERENCE_DATA__MAX_DIFF_PER_CHANNEL: self._max_diff_per_channel, | 213 KEY__DIFFERENCES__MAX_DIFF_PER_CHANNEL: self._max_diff_per_channel, |
| 214 KEY__DIFFERENCE_DATA__PERCEPTUAL_DIFF: self._perceptual_difference, | 214 KEY__DIFFERENCES__PERCEPTUAL_DIFF: self._perceptual_difference, |
| 215 } | 215 } |
| 216 | 216 |
| 217 | 217 |
| 218 class ImageDiffDB(object): | 218 class ImageDiffDB(object): |
| 219 """ Calculates differences between image pairs, maintaining a database of | 219 """ Calculates differences between image pairs, maintaining a database of |
| 220 them for download.""" | 220 them for download.""" |
| 221 | 221 |
| 222 def __init__(self, storage_root): | 222 def __init__(self, storage_root): |
| 223 """ | 223 """ |
| 224 Args: | 224 Args: |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 442 |
| 443 Args: | 443 Args: |
| 444 expected_image_locator: locator string pointing at expected image | 444 expected_image_locator: locator string pointing at expected image |
| 445 actual_image_locator: locator string pointing at actual image | 445 actual_image_locator: locator string pointing at actual image |
| 446 | 446 |
| 447 Returns: already-sanitized locator where the diffs between expected and | 447 Returns: already-sanitized locator where the diffs between expected and |
| 448 actual images can be found | 448 actual images can be found |
| 449 """ | 449 """ |
| 450 return "%s-vs-%s" % (_sanitize_locator(expected_image_locator), | 450 return "%s-vs-%s" % (_sanitize_locator(expected_image_locator), |
| 451 _sanitize_locator(actual_image_locator)) | 451 _sanitize_locator(actual_image_locator)) |
| OLD | NEW |