MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / save_diff_image

Function save_diff_image

lib/matplotlib/testing/compare.py:508–538  ·  view source on GitHub ↗

Parameters ---------- expected : str File path of expected image. actual : str File path of actual image. output : str File path to save difference image to.

(expected, actual, output)

Source from the content-addressed store, hash-verified

506
507
508def save_diff_image(expected, actual, output):
509 """
510 Parameters
511 ----------
512 expected : str
513 File path of expected image.
514 actual : str
515 File path of actual image.
516 output : str
517 File path to save difference image to.
518 """
519 expected_image = _load_image(expected)
520 actual_image = _load_image(actual)
521 actual_image, expected_image = crop_to_same(
522 actual, actual_image, expected, expected_image)
523 expected_image = np.array(expected_image, float)
524 actual_image = np.array(actual_image, float)
525 if expected_image.shape != actual_image.shape:
526 raise ImageComparisonFailure(
527 f"Image sizes do not match expected size: {expected_image.shape} "
528 f"actual size {actual_image.shape}")
529 abs_diff = np.abs(expected_image - actual_image)
530
531 # expand differences in luminance domain
532 abs_diff *= 10
533 abs_diff = np.clip(abs_diff, 0, 255).astype(np.uint8)
534
535 if abs_diff.shape[2] == 4: # Hard-code the alpha channel to fully solid
536 abs_diff[:, :, 3] = 255
537
538 Image.fromarray(abs_diff).save(output, format="png")

Callers

nothing calls this directly

Calls 5

_load_imageFunction · 0.85
crop_to_sameFunction · 0.85
saveMethod · 0.80
clipMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…