2

For a few hours now, I've been trying to figure out how to view an image I imported with pillow. So far, I got rid of all errors, but it just shows the exact filename of the photo, the image isn't showing up, please help me fix this.

This is what I have so far:

from PIL import Image

img = Image.open("image.jpg")

print(img)
AJN
  • 29
  • 1
  • 3
  • You say you're having issues importing the image but then you say it "isn't showing up". I believe you're trying to actually open the image to see it? Or are you trying use it somewhere? Currently there's nothing wrong with your code, it is working fine but all this does is load the image into memory as an Image object. – Jab May 11 '19 at 02:20
  • You haven't done anything to display the image. Your `img` is a variable referencing the opened `Image`. – John Anderson May 11 '19 at 02:20
  • Possible duplicate of [Showing an image from console in Python](https://stackoverflow.com/questions/1413540/showing-an-image-from-console-in-python) – Jab May 11 '19 at 02:22
  • Well, how do I get it to show on the window? – AJN May 11 '19 at 02:24
  • Please refer to the link above, This is a duplicate of that question. Use `img.show()`. – Jab May 11 '19 at 02:27

3 Answers3

0

From the docs the function to show an image is

Image.show(title=None, command=None)

So to display an image you can do

from PIL import Image

img = Image.open("image.jpg")
img.show()
nathancy
  • 42,661
  • 14
  • 115
  • 137
0

Sir Please try this code

from PIL import Image
import matplotlib.pyplot as plt
%matplotlib inline

a=Image.open("F:\\FYP DATASET\\images\\train\\10_left.jpeg")
a

try by removing print statement and adding matplotlib library. Purpose of %Matplotlib inline in Python:

By just writing variable without print statement will display the image in notebook and by img.show() It will display image in Photo Viewer (Windows photo viwer) etc depends on what you are using.

Sohaib Anwaar
  • 1,517
  • 1
  • 12
  • 29
0
from PIL import Image

img = Image.open("man.png")
img.show()
PythonProgrammi
  • 22,305
  • 3
  • 41
  • 34