FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixed SVG-as-text image comparison tests. by tfpf · Pull Request #23350 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .svg  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
21 changes: 15 additions & 6 deletions lib/matplotlib/testing/compare.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,16 @@ def calculate_rms(expected_image, actual_image):
# 16-bit depth, as Pillow converts these to RGB incorrectly.


def _load_image(path):
img = Image.open(path)
# In an RGBA image, if the smallest value in the alpha channel is 255, all
# values in it must be 255, meaning that the image is opaque. If so,
# discard the alpha channel so that it may compare equal to an RGB image.
if img.mode != "RGBA" or img.getextrema()[3][0] == 255:
Comment thread
QuLogic marked this conversation as resolved.
img = img.convert("RGB")
return np.asarray(img)


def compare_images(expected, actual, tol, in_decorator=False):
"""
Compare two "image" files checking differences within a tolerance.
Expand Down Expand Up @@ -435,9 +445,9 @@ def compare_images(expected, actual, tol, in_decorator=False):
actual = convert(actual, cache=True)
expected = convert(expected, cache=True)

# open the image files and remove the alpha channel (if it exists)
expected_image = np.asarray(Image.open(expected).convert("RGB"))
actual_image = np.asarray(Image.open(actual).convert("RGB"))
# open the image files
expected_image = _load_image(expected)
actual_image = _load_image(actual)

actual_image, expected_image = crop_to_same(
actual, actual_image, expected, expected_image)
Expand Down Expand Up @@ -486,9 +496,8 @@ def save_diff_image(expected, actual, output):
output : str
File path to save difference image to.
"""
# Drop alpha channels, similarly to compare_images.
expected_image = np.asarray(Image.open(expected).convert("RGB"))
actual_image = np.asarray(Image.open(actual).convert("RGB"))
expected_image = _load_image(expected)
actual_image = _load_image(actual)
actual_image, expected_image = crop_to_same(
actual, actual_image, expected, expected_image)
expected_image = np.array(expected_image).astype(float)
Expand Down
Loading

Back | FazBrowse Home | New Git URL