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

Skip to content

Commit 69cf385

Browse files
authored
Merge pull request #23659 from anntzer/sdi
Simplify/fix save_diff_image.
2 parents 3835c3e + 50948d4 commit 69cf385

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

lib/matplotlib/testing/compare.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -506,21 +506,13 @@ def save_diff_image(expected, actual, output):
506506
raise ImageComparisonFailure(
507507
"Image sizes do not match expected size: {} "
508508
"actual size {}".format(expected_image.shape, actual_image.shape))
509-
abs_diff_image = np.abs(expected_image - actual_image)
509+
abs_diff = np.abs(expected_image - actual_image)
510510

511511
# expand differences in luminance domain
512-
abs_diff_image *= 255 * 10
513-
save_image_np = np.clip(abs_diff_image, 0, 255).astype(np.uint8)
514-
height, width, depth = save_image_np.shape
512+
abs_diff *= 10
513+
abs_diff = np.clip(abs_diff, 0, 255).astype(np.uint8)
515514

516-
# The PDF renderer doesn't produce an alpha channel, but the
517-
# matplotlib PNG writer requires one, so expand the array
518-
if depth == 3:
519-
with_alpha = np.empty((height, width, 4), dtype=np.uint8)
520-
with_alpha[:, :, 0:3] = save_image_np
521-
save_image_np = with_alpha
515+
if abs_diff.shape[2] == 4: # Hard-code the alpha channel to fully solid
516+
abs_diff[:, :, 3] = 255
522517

523-
# Hard-code the alpha channel to fully solid
524-
save_image_np[:, :, 3] = 255
525-
526-
Image.fromarray(save_image_np).save(output, format="png")
518+
Image.fromarray(abs_diff).save(output, format="png")

0 commit comments

Comments
 (0)