1

The code:

>>> import Image
>>> img = Image.open("mini.jpg")
>>> print img.getdata()

return: ImagingCore object at 0x7fb02637f330

I know that this represent an object of Python Image Libraries (PIL) in hexadecimal base.

How can I translate this number code properly? It's a *jpg, size 34x34.

Anthon
  • 69,918
  • 32
  • 186
  • 246
Jhon Gaza
  • 53
  • 1
  • 7
  • 2
    It's the images address in memory. What do you want to translate it to? You couldn't display the image on the command line, you'd need a GUI library like tkinter. – Paul Rooney Apr 30 '15 at 22:09
  • If you want to get information on the object, it has a whole bunch of attributes and methods that you can use. Which ones you use depends on which information you want to get. And since only you know which information you want, you should read in help/docs for yourself, write the code, and then, if there's anything you can't find or figure out, ask a question here. – abarnert Apr 30 '15 at 22:11
  • possible duplicate of [Display jpg images in python](http://stackoverflow.com/questions/1356255/display-jpg-images-in-python) – Michael Roland Apr 30 '15 at 22:12
  • @PaulRooney well, he could run the image through `libaa` or similar and display an ASCII art rendering of it on the command line. :) – abarnert Apr 30 '15 at 22:13
  • @MichaelRoland it doesn't look like a duplicate. This question is asking how to get information about an image to print; that one is about displaying an image on a Tkinter button. They're only vaguely related. – abarnert Apr 30 '15 at 22:13
  • @abarnert Interesting I thought someone might come up with a way to display it on the command line. I'll have to try that myself. – Paul Rooney Apr 30 '15 at 22:15
  • @abarnert Agreed (and retracted my vote). I interpreted the question as "I want to print (display) the image. How do I do that?" – Michael Roland Apr 30 '15 at 22:20
  • As a side note, if you're doing `import Image` rather than `from PIL import Image`, that implies that (a) you're using the ancient `PIL` instead of its modern fork [`Pillow`](http://pillow.readthedocs.org/), and (b) you installed it in a way that hasn't been recommended in a very long time. I'd suggest uninstalling it and doing `pip install pillow`. (And if you're learning from an ancient tutorial that disagrees, find a newer tutorial.) – abarnert Apr 30 '15 at 23:05
  • possible duplicate of [In Python, what does '' mean?](http://stackoverflow.com/questions/19333598/in-python-what-does-function-at-mean) – tripleee May 03 '15 at 08:20

2 Answers2

1

You can't "translate this number properly", because all that number means is where in memory Pillow is storing the object, and there's nothing useful you can translate that to.

If you're trying to get information out of an object in Python, you do that by accessing its attributes and methods.

The object returned by Image.open is an Image.Image object. It has attributes like mode (a string like "RGB"), and methods like getextrema (a pair of minimum and maximum pixel values, like (3, 237)).

The object returned by its getdata method is just a flat sequence of pixel values. It doesn't have much useful information to get, unless you actually want to iterate over those pixel values. So, you can't "translate" that into anything useful.

So, if you want some information about the image, you have to know which information you want, then look in the docs to see how that information is accessed. For example, if you want the mode of the image:

>>> import Image
>>> img = Image.open("mini.jpg")
>>> print img.mode
RGB
abarnert
  • 354,177
  • 51
  • 601
  • 671
0

If you print(list(image.getdata()) you will see that the list items are the RGB byte values for each pixel. Given your image size you will have 34 x 34 list items.

Using python 10.4 I have just tested it and it's possible to do this:

i_data = image.getdata()
print(i_data[0],  i_data[1])  # that will show you the first 2 tuples.

Note they are tuples so the data can not be modified.

If you want to manipulate the image there are a number of PIL (pillow) methods. The documentation at https://pillow.readthedocs.io/en/stable/reference/Image.html may help.

ye olde noobe
  • 1,186
  • 6
  • 12