Skip to content
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

Displaying images in Google Colab #5286

Closed
Kipkurui-mutai opened this issue Feb 25, 2021 · 16 comments · Fixed by #5289
Closed

Displaying images in Google Colab #5286

Kipkurui-mutai opened this issue Feb 25, 2021 · 16 comments · Fixed by #5289

Comments

@Kipkurui-mutai
Copy link
Contributor

Kipkurui-mutai commented Feb 25, 2021

What did you do?

Image.show()

What did you expect to happen?

Display the Image

What actually happened?

<PIL.PngImagePlugin.PngImageFile image mode=RGB size=450x253 at 0x7FFB7B401C50>

What are your OS, Python and Pillow versions?

  • OS: Windows
  • Python: 3.9
  • Pillow: 7.0.0
display(image)
@radarhere radarhere changed the title Displaying images according to the documentation. Displaying images according to the documentation Feb 25, 2021
@radarhere
Copy link
Member

At the moment, this is somewhat confusing.

For one thing, you can't simply call Image.show() - unless Image is the name of your variable.
You could

from PIL import Image
im = Image.new("RGB", (100, 100))
im.show()

For another, where does the display() method come from? That's not a part of Pillow.

Would you be able to provide a more complete example?

@Kipkurui-mutai
Copy link
Contributor Author

Capture
So I tried im.show() and couldn't print anything. I tried display(im) and it worked for me.

@Kipkurui-mutai
Copy link
Contributor Author

@radarhere I am using Colab.

@Kipkurui-mutai
Copy link
Contributor Author

@radarhere I have tried im.show() using my terminal and it works fine. I do not know why it's not working on https://colab.research.google.com

@nulano
Copy link
Contributor

nulano commented Feb 26, 2021

From https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.show:

Displays this image. This method is mainly intended for debugging purposes.

This method calls PIL.ImageShow.show() internally. You can use PIL.ImageShow.register() to override its default behaviour.

The image is first saved to a temporary file. By default, it will be in PNG format.

On Unix, the image is then opened using the display, eog or xv utility, depending on which one can be found.

On macOS, the image is opened with the native Preview application.

On Windows, the image is opened with the standard PNG display utility.

The display, eog and xv utilities require a display; Google Colab doesn't give you access to the display, only a terminal.

@Kipkurui-mutai
Copy link
Contributor Author

Kipkurui-mutai commented Feb 26, 2021

@nulano Other libraries like those for visualization are displaying their images on Colab well. Does this mean it cannot be done with Pillow?

@radarhere
Copy link
Member

I've created PR #5289 to suggest adding this functionality to Pillow. Even if it is merged though, it might take a while to get bundled into Google Colab, since the current version in Colab is Pillow 7.0, a bit behind the current version of 8.1.0.

@Kipkurui-mutai
Copy link
Contributor Author

Kipkurui-mutai commented Feb 26, 2021

@radarhere and @nulano will this make me a contributor or I must write code?

@radarhere
Copy link
Member

No, 'Contributors' isn't a manual list that we add you to, it's an automatic one - you must write a commit, and have that commit be merged in.

@Kipkurui-mutai
Copy link
Contributor Author

@radarhere so how can I contribute ? I see almost everything is pretty much done.

@radarhere
Copy link
Member

If you're asking what the next step is to the change being accepted, this is the review stage. So anyone, yourself included, can take a look at it and make comments for how it could be improved, or create a pull request in my Pillow fork with commits that they would like to be added to it.

After that, one of the Pillow members needs to decide to merge it, and then it will be part of the next Pillow release. So the soonest it could be released is April 1.

@Kipkurui-mutai
Copy link
Contributor Author

@radarhere I really wanted to contribute to that functionality. Guess I should probably look out for other improvements and Create a PR myself.

@hugovk
Copy link
Member

hugovk commented Feb 28, 2021

A good place to start is with documentation.

You could add #5289 to the release notes, perhaps in the API Additions section?

https://github.com/python-pillow/Pillow/blob/master/docs/releasenotes/8.2.0.rst

And does it also belong elsewhere in docs?

@Kipkurui-mutai
Copy link
Contributor Author

@hugovk Where exactly, I am new in contributing to open source, 49/50 checks has already been passed. Does this mean #5289 has already been updated in the release notes?

@hugovk
Copy link
Member

hugovk commented Feb 28, 2021

No, the checks are unrelated. That PR doesn't have release notes. If you'd like to contribute them, you can edit https://github.com/python-pillow/Pillow/blob/master/docs/releasenotes/8.2.0.rst and create a new pull request.

@radarhere
Copy link
Member

It's also apparent that https://pillow--5289.org.readthedocs.build/en/5289/reference/ImageShow.html doesn't mention IPythonViewer at all. If you'd like to fix that, you can modify https://github.com/python-pillow/Pillow/blob/master/docs/reference/ImageShow.rst.

Once your change is ready, you can go to radarhere/Pillow@ipythonviewer...Kipkurui-mutai:master to create a pull request for #5289 specifically.

@radarhere radarhere changed the title Displaying images according to the documentation Displaying images in Google Colab Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants