Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't show an image using PIL on google colab

I am trying to use PIL to show an image. I know that I can use other modules to do that. I am working on google colab. But I can't figure out why PIL is not showing output image.

% matplotlib inline
import numpy as np
import PIL
im=Image.open('/content/drive/My Drive/images-process.jpeg')
print(im.width, im.height, im.mode, im.format, type(im))
im.show()

output: 739 415 RGB JPEG < class 'PIL.JpegImagePlugin.JpegImageFile'>

like image 799
Nemesis Avatar asked Feb 03 '20 07:02

Nemesis


People also ask

How do I display an image using PIL?

Python – Display Image using PIL To show or display an image in Python Pillow, you can use show() method on an image object. The show() method writes the image to a temporary file and then triggers the default program to display that image. Once the program execution is completed, the temporary file will be deleted.

How do I read an image from Google Drive in Colab?

The second method, insert an image from Google drive: upload your image to the same folder where your colab notebook is residing. Once done, head over to the drive folder set the permission to “Anyone with the link can view”.

How do I add an image to a colab file?

Right-click your image and you will find an option to get a sharable link. On selecting 'Get shareable link', Google will create and display sharable link for the particular image. The format may change in the future but all we need to embed our image is the <ID of image> from URL.

Is there a way to display images on Google Colab?

The display, eog and xv utilities require a display; Google Colab doesn't give you access to the display, only a terminal. Sorry, something went wrong. @nulano Other libraries like those for visualization are displaying their images on Colab well.

How do I open a PNG file in Google Colab?

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. Sorry, something went wrong. @nulano Other libraries like those for visualization are displaying their images on Colab well.

How do I use PIL imageshow () internally?

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.

How to add images to Google Notebook?

First, open google drive & upload the image on the drive. Select t h e uploaded image, right-click on it, get a sharable link & copy it. Step 2: Upload on Google Colab Open Google Colab Notebook & add text block where you want to include the image.


2 Answers

Instead of

im.show()

Try just

im

Colab should try to display it on its own. See example notebook

like image 110
korakot Avatar answered Sep 22 '22 18:09

korakot


Use

display(im)

instead of im.show() or im.

When using these options after multiple lines or in a loop, im won't work.

like image 22
Aishwarya Harpale Avatar answered Sep 19 '22 18:09

Aishwarya Harpale