-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fixed imsave() saving incorrect color map #29203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
07226ab
e491c52
e4bdd84
c16b4b0
3faf4e2
0df1f51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -28,6 +28,7 @@ | |||
Affine2D, BboxBase, Bbox, BboxTransform, BboxTransformTo, | ||||
IdentityTransform, TransformedBbox) | ||||
|
||||
|
||||
_log = logging.getLogger(__name__) | ||||
|
||||
# map interpolation strings to module constants | ||||
|
@@ -1093,6 +1094,7 @@ def set_data(self, x, y, A): | |||
""" | ||||
Set the grid for the pixel centers, and the pixel values. | ||||
|
||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
Parameters | ||||
---------- | ||||
x, y : 1D array-like | ||||
|
@@ -1582,6 +1584,10 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None, | |||
_api.check_in_list(('upper', 'lower'), origin=origin) | ||||
if origin == "lower": | ||||
arr = arr[::-1] | ||||
|
||||
if (isinstance(arr, list)): | ||||
arr = np.asarray(arr, dtype=np.uint8) | ||||
|
||||
Comment on lines
+1587
to
+1590
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move the format coersion above the origin handling. While the reversal ( Also
|
||||
if (isinstance(arr, memoryview) and arr.format == "B" | ||||
and arr.ndim == 3 and arr.shape[-1] == 4): | ||||
# Such an ``arr`` would also be handled fine by sm.to_rgba below | ||||
|
@@ -1630,6 +1636,7 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None, | |||
background = PIL.Image.new("RGB", pil_shape, color) | ||||
background.paste(image, image) | ||||
image = background | ||||
|
||||
pil_kwargs.setdefault("format", format) | ||||
pil_kwargs.setdefault("dpi", (dpi, dpi)) | ||||
image.save(fname, **pil_kwargs) | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.