-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: I give an RGB image to imsave but I don't have the right color map! #29183
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
Comments
The source of the problem is that in import matplotlib.pyplot as plt
import numpy as np
I = plt.imread("notre-dame.jpg")
J = np.zeros_like(I)
# RGB version of the image with only one plane non-zero
J[..., 0] = I[..., 0]
K = np.zeros_like(I)
K[..., 0] = I[..., 1]
L = np.zeros_like(I)
L[..., 0] = I[..., 2]
# share the axis so that panning / zooming on one pans/zooms on all
fig, axs = plt.subplots(4, figsize=(28, 10), sharex='all', sharey='all')
# loop over axes, data, and title strings
for ax, data, title in zip(
axs,
(I, J, K, L),
("Image complete", "Composante rouge", "Composante bleue", "Composante verte"),
):
ax.imshow(data)
ax.set_title(title)
fig.suptitle("Image de Notre-Dame", x=0.51, y=0.93)
fig.savefig("Notre-Dame_composante_ex1.png", dpi=750, bbox_inches="tight")
fig.savefig("Notre-Dame_composante_ex1.pdf", dpi=750, bbox_inches="tight")
plt.imsave("Notre-Dame_rouge.png", J) # The problem is here!
plt.show() As a short-term fix you can also do |
Good first issue - notes for new contributorsThis issue is suited to new contributors because it does not require understanding of the We do not assign issues. Check the Development section in the sidebar for linked pull If something is unclear, please reach out on any of our communication |
This is a good first issue as it should require no API choices and we have a good reference for the expected behavior already in the code base. The issue is that when passing a list-of-list-of-list to The steps are:
|
Hi I am a new contributor to opensource and believe I can fix this could I be assigned to this issue? |
We do not assign issues. Please review https://matplotlib.org/stable/devel/index and open a PR when you are ready! |
Thank you so much for your help...it is very useful, I will try to use arrays! |
It is the first repo where i fond kindness and attention, it is really appreciated! |
Now it's just a code issue...I don't understand why I get that: |
|
🤦🏻 as noteed, should be J[..., 0] = I[..., 0]
K = np.zeros_like(I)
K[..., 1] = I[..., 1]
L = np.zeros_like(I)
L[..., 2] = I[..., 2] and |
Thank you very much! plt.imsave("Notre-Dame_rouge.png", np.asarray(J, dtype=np.int8))
OverflowError: Python integer 128 out of bounds for int8 |
@zef126 Can you please try |
…of-list and saved the correct image.
(Hi everyone, this is my first time commenting on an issue here, so please let me know if I’ve missed anything! 😊) The suggestion to convert lists of lists to a NumPy array before using Here are a few thoughts:
I’d be happy to contribute to any of these changes. Looking forward to hearing your thoughts! |
I anticipate it will. - There are still some changes to be done. |
Is there any help still required with this as I want to make my first open source contributions. |
@shreyas-koduvayur There's currently no help needed. We're waiting for the repsonse of the author of #29203. If there's no feedback in a couple of days, you could take over. |
@aragan22 This is not adding meaningfully to the issue. You are only rewriting the original restating the original minimal example with comments - but the example and issue is well understood. Nobody with the capability of fixing the issue needs these comments. Please think carefully to not post repetitive or unneeded stuff. |
Apologies, I did not mean to comment that portion. That was simply for myself as I tried to understand the issue and work around it in my own way. Thank you for pointing this out, apologies again for the confusion. |
is this issue still up and can i work in this ? |
@Dronten yes it looks like #29203 has stalled so you are welcome to go ahead. Please see our contributors’ guide: |
Has the issue been solved? Else I'd like to take over. |
@Aftabby it looks like #29203 has stalled so you are welcome to go ahead. Please see our contributors’ guide: |
Hey there, I tried running the code in the snippet and it shows the expected output. Does this mean the issue can be closed? |
Yes, closed by #29931. |
Bug summary
When I give an RGB image as a list of list of list to imsave, I don't have the right colormap and there is no rgb colormap!
Code for reproduction
Actual outcome
Expected outcome
The red one in a png image!
Additional information
The original image
Operating system
Win 11
Matplotlib Version
3.9.2
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
3.11.10
Jupyter version
No response
Installation
conda
The text was updated successfully, but these errors were encountered: