|
10 | 10 | from matplotlib.testing.noseclasses import ImageComparisonFailure
|
11 | 11 | from matplotlib.testing import image_util
|
12 | 12 | from matplotlib import _png
|
| 13 | +from distutils import version |
13 | 14 | import math
|
14 | 15 | import operator
|
15 | 16 | import os
|
@@ -225,20 +226,39 @@ def compare_images( expected, actual, tol, in_decorator=False ):
|
225 | 226 | actualImage, expectedImage = crop_to_same(actual, actualImage, expected, expectedImage)
|
226 | 227 |
|
227 | 228 | # normalize the images
|
228 |
| - expectedImage = image_util.autocontrast( expectedImage, 2 ) |
229 |
| - actualImage = image_util.autocontrast( actualImage, 2 ) |
| 229 | + # expectedImage = image_util.autocontrast( expectedImage, 2 ) |
| 230 | + # actualImage = image_util.autocontrast( actualImage, 2 ) |
230 | 231 |
|
231 | 232 | # compare the resulting image histogram functions
|
232 |
| - rms = 0 |
233 |
| - bins = np.arange(257) |
234 |
| - for i in xrange(0, 3): |
235 |
| - h1p = expectedImage[:,:,i] |
236 |
| - h2p = actualImage[:,:,i] |
| 233 | + expected_version = version.LooseVersion("1.6") |
| 234 | + found_version = version.LooseVersion(np.__version__) |
237 | 235 |
|
238 |
| - h1h = np.histogram(h1p, bins=bins)[0] |
239 |
| - h2h = np.histogram(h2p, bins=bins)[0] |
| 236 | + # On Numpy 1.6, we can use bincount with minlength, which is much faster than |
| 237 | + # using histogram |
| 238 | + if found_version >= expected_version: |
| 239 | + rms = 0 |
| 240 | + |
| 241 | + for i in xrange(0, 3): |
| 242 | + h1p = expectedImage[:,:,i] |
| 243 | + h2p = actualImage[:,:,i] |
| 244 | + |
| 245 | + h1h = np.bincount(h1p.ravel(), minlength=256) |
| 246 | + h2h = np.bincount(h2p.ravel(), minlength=256) |
| 247 | + |
| 248 | + rms += np.sum(np.power((h1h-h2h), 2)) |
| 249 | + else: |
| 250 | + rms = 0 |
| 251 | + ns = np.arange(257) |
| 252 | + |
| 253 | + for i in xrange(0, 3): |
| 254 | + h1p = expectedImage[:,:,i] |
| 255 | + h2p = actualImage[:,:,i] |
| 256 | + |
| 257 | + h1h = np.histogram(h1p, bins=bins)[0] |
| 258 | + h2h = np.histogram(h2p, bins=bins)[0] |
| 259 | + |
| 260 | + rms += np.sum(np.power((h1h-h2h), 2)) |
240 | 261 |
|
241 |
| - rms += np.sum(np.power((h1h-h2h), 2)) |
242 | 262 | rms = np.sqrt(rms / (256 * 3))
|
243 | 263 |
|
244 | 264 | diff_image = make_test_filename(actual, 'failed-diff')
|
|
0 commit comments