@@ -250,6 +250,42 @@ def crop_to_same(actual_path, actual_image, expected_path, expected_image):
250
250
actual_image = actual_image [int (aw / 2 - ew / 2 ):int (aw / 2 + ew / 2 ),int (ah / 2 - eh / 2 ):int (ah / 2 + eh / 2 )]
251
251
return actual_image , expected_image
252
252
253
+ def calculate_rms (expectedImage , actualImage ):
254
+ # compare the resulting image histogram functions
255
+ expected_version = version .LooseVersion ("1.6" )
256
+ found_version = version .LooseVersion (np .__version__ )
257
+
258
+ # On Numpy 1.6, we can use bincount with minlength, which is much faster than
259
+ # using histogram
260
+ if found_version >= expected_version :
261
+ rms = 0
262
+
263
+ for i in xrange (0 , 3 ):
264
+ h1p = expectedImage [:,:,i ]
265
+ h2p = actualImage [:,:,i ]
266
+
267
+ h1h = np .bincount (h1p .ravel (), minlength = 256 )
268
+ h2h = np .bincount (h2p .ravel (), minlength = 256 )
269
+
270
+ rms += np .sum (np .power ((h1h - h2h ), 2 ))
271
+ else :
272
+ rms = 0
273
+ bins = np .arange (257 )
274
+
275
+ for i in xrange (0 , 3 ):
276
+ h1p = expectedImage [:,:,i ]
277
+ h2p = actualImage [:,:,i ]
278
+
279
+ h1h = np .histogram (h1p , bins = bins )[0 ]
280
+ h2h = np .histogram (h2p , bins = bins )[0 ]
281
+
282
+ rms += np .sum (np .power ((h1h - h2h ), 2 ))
283
+
284
+ rms = np .sqrt (rms / (256 * 3 ))
285
+
286
+ return rms
287
+
288
+
253
289
def compare_images ( expected , actual , tol , in_decorator = False ):
254
290
'''Compare two image files - not the greatest, but fast and good enough.
255
291
@@ -287,33 +323,7 @@ def compare_images( expected, actual, tol, in_decorator=False ):
287
323
expected_version = version .LooseVersion ("1.6" )
288
324
found_version = version .LooseVersion (np .__version__ )
289
325
290
- # On Numpy 1.6, we can use bincount with minlength, which is much faster than
291
- # using histogram
292
- if found_version >= expected_version :
293
- rms = 0
294
-
295
- for i in xrange (0 , 3 ):
296
- h1p = expectedImage [:,:,i ]
297
- h2p = actualImage [:,:,i ]
298
-
299
- h1h = np .bincount (h1p .ravel (), minlength = 256 )
300
- h2h = np .bincount (h2p .ravel (), minlength = 256 )
301
-
302
- rms += np .sum (np .power ((h1h - h2h ), 2 ))
303
- else :
304
- rms = 0
305
- bins = np .arange (257 )
306
-
307
- for i in xrange (0 , 3 ):
308
- h1p = expectedImage [:,:,i ]
309
- h2p = actualImage [:,:,i ]
310
-
311
- h1h = np .histogram (h1p , bins = bins )[0 ]
312
- h2h = np .histogram (h2p , bins = bins )[0 ]
313
-
314
- rms += np .sum (np .power ((h1h - h2h ), 2 ))
315
-
316
- rms = np .sqrt (rms / (256 * 3 ))
326
+ rms = calculate_rms (expectedImage , actualImage )
317
327
318
328
diff_image = make_test_filename (actual , 'failed-diff' )
319
329
@@ -322,6 +332,21 @@ def compare_images( expected, actual, tol, in_decorator=False ):
322
332
os .unlink (diff_image )
323
333
return None
324
334
335
+ # For Agg-rendered images, we can retry by ignoring pixels with
336
+ # differences of only 1
337
+ if extension == 'png' :
338
+ # Remove differences of only 1
339
+ diffImage = np .abs (np .asarray (actualImage , dtype = np .int ) -
340
+ np .asarray (expectedImage , dtype = np .int ))
341
+ actualImage = np .where (diffImage <= 1 , expectedImage , actualImage )
342
+
343
+ rms = calculate_rms (expectedImage , actualImage )
344
+
345
+ if ( (rms / 10000.0 ) <= tol ):
346
+ if os .path .exists (diff_image ):
347
+ os .unlink (diff_image )
348
+ return None
349
+
325
350
save_diff_image ( expected , actual , diff_image )
326
351
327
352
if in_decorator :
0 commit comments