Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c39d9dc

Browse files
Michael Weltermdboom
Michael Welter
authored andcommitted
fixed: compare_images for older numpy versions. added: backend_pdf allows numpy.float32 in pdfRepr
1 parent 22c3978 commit c39d9dc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/matplotlib/testing/compare.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,36 @@ def compare_images( expected, actual, tol, in_decorator=False ):
306306
expectedImage = expectedImage.astype(np.int16)
307307
actualImage = actualImage.astype(np.int16)
308308

309+
# compare the resulting image histogram functions
310+
expected_version = version.LooseVersion("1.6")
311+
found_version = version.LooseVersion(np.__version__)
312+
313+
# On Numpy 1.6, we can use bincount with minlength, which is much faster than
314+
# using histogram
315+
if found_version >= expected_version:
316+
rms = 0
317+
318+
for i in xrange(0, 3):
319+
h1p = expectedImage[:,:,i]
320+
h2p = actualImage[:,:,i]
321+
322+
h1h = np.bincount(h1p.ravel(), minlength=256)
323+
h2h = np.bincount(h2p.ravel(), minlength=256)
324+
325+
rms += np.sum(np.power((h1h-h2h), 2))
326+
else:
327+
rms = 0
328+
ns = np.arange(257)
329+
330+
for i in xrange(0, 3):
331+
h1p = expectedImage[:,:,i]
332+
h2p = actualImage[:,:,i]
333+
334+
h1h = np.histogram(h1p, bins=ns)[0]
335+
h2h = np.histogram(h2p, bins=ns)[0]
336+
337+
rms += np.sum(np.power((h1h-h2h), 2))
338+
309339
rms = calculate_rms(expectedImage, actualImage)
310340

311341
diff_image = make_test_filename(actual, 'failed-diff')

0 commit comments

Comments
 (0)