0

Below is my code for opening an image:

import Image

filename = "Golden-Gauranga.png"
image = Image.open(filename, "r")
image.show()

However, the image does not open. Nothing happens.

10
  • 1
    "The program does not seem to contain any errors." Besides the obvious indentation fail. Show the exact code and tell what goes wrong exactly.
    – user1804599
    Mar 27, 2014 at 13:16
  • Please post the code exactly as it is in the source and also explain what you mean by 'image does not open'. Is there an error? Does the program run and nothing happens? Details. Mar 27, 2014 at 13:18
  • I apologize for not being clear. Nothing happens after the program is run.
    – Nitaai
    Mar 27, 2014 at 13:21
  • 1
    There can be another module named Image. Did you try from PIL import Image?
    – Selcuk
    Mar 27, 2014 at 13:24
  • Yes I did. Still the image does not open.
    – Nitaai
    Mar 27, 2014 at 13:25

2 Answers 2

1

You could try using cv2 and pyplot instead of Image. First you need to install OpenCV and the other modules, and then change your code to something like

import cv2
import numpy
import matplotlib.pyplot as plt
filename = "Golden-Gauranga.png"
im = cv2.imread(filename, -1)
imarray = numpy.array(im)
plt.imshow(imarray)
plt.show
0

For now, I am opening the image file using the below code:

import os
os.system("gvfs-open today")

I am on an Ubuntu system and today is the name of the image file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.