2

On this Image

enter image description here

I am trying to apply:

from PIL import Image
img0 = PIL.Image.open('Entertainment.jpg')
img0 = np.float32(img0)
showarray(img0/255.0)

And I get this error:

TypeErrorTraceback (most recent call last)
<ipython-input-20-c181acf634a8> in <module>()
      2 img0 = PIL.Image.open('Entertainment.jpg')
      3 img0 = np.float32(img0)
----> 4 showarray(img0/255.0)

<ipython-input-8-b253b18ff9a7> in showarray(a, fmt)
     11     f = BytesIO()
     12     PIL.Image.fromarray(a).save(f, fmt)
---> 13     display(Image(data=f.getvalue()))
     14 
     15 def visstd(a, s=0.1):

TypeError: 'module' object is not callable

I can't understand why.

What is not callable here?
How can I just display the image?

2 Answers 2

2

The problem may stem from how you've imported the display() function. If your import line is:

import IPython.display as display

then you need to invoke display.display() to show the image. For example:

import IPython.display as display
my_image = Image.open('something.jpg')
display.display(my_image)

If you instead invoke the function as

import IPython.display as display
my_image = Image.open('something.jpg')
display(my_image) # INCORRECT
# TypeError: 'module' object is not callable

then you will indeed get the error message in your original post because display is referring to a module, not a function.

Alternatively, if you import the display() function in the following manner, your code will work:

from IPython.display import display
my_image = Image.open('something.jpg')
display(my_image)
Sign up to request clarification or add additional context in comments.

Comments

1

Image is a module that you imported

from PIL import Image

You can't call it

Image(data=f.getvalue())

There's a show method that may be useful

img0 = PIL.Image.open('Entertainment.jpg')
img0.show() 

5 Comments

Hi, thx for the answer, but removing that import also, I get the same error. How to fix it i.e. display the image? The code works here github.com/tensorflow/tensorflow/blob/r0.10/tensorflow/examples/… but not on my jupyter notebook.
If you remove the import, then you probably get a different error saying that Image isn't defined.
.show() doesn't work 'numpy.ndarray' object has no attribute 'show' . AM I missing anything importtant ?
Well, I'm not sure what you're showarray function is doing, but still, Image is a module and you can't call it. If you want to display the image, see my update. I can't speak for a jupyter notebook
You've converted it to a Numpy float32 array in between opening and showing. I'm not sure why you need to do that

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.