+ 3
How to access individual pixels of image in Python. Pls help
11 Réponses
+ 3
Use imageio lib.
𝗖𝗼𝗱𝗲,
import imageio
image=imageio.imread("path to image")
------------------------------------------------------
image now contains a "image type of array" which is a numpy array (not sure if it is , but numpy methods worked on it) . Yes you need to learn about numpy arrays if you want to deal with that data.
In case you aren't sure about numpy methods working on "image type of array", convert it to numpy array so that all the numpy methods work on it.
You can also look up the official docs for imageio.imread method that might help you in understanding what it is and how to deal with it.
It is nothing more than a 3 dimensional array . A bit complicated to understand but if someone plays around with small examples they might get hang of it (i am still trying to find my way around it , lol not that easy except simple use cases).
For example , if you want to get the first pixel data then the command for it would be following ,
print(image[0, 0])
+ 2
Alternatively you can take a look at the pillow module.
https://ehmatthes.github.io/pcc_2e/beyond_pcc/pillow/
+ 2
Rishi i think you are right . But when we print the array it shows the actual array instead of its address (it would have shown the address if it was a language like c)
+ 2
Thanks for your responses. They were really helpful
+ 1
Rishi 3 dimensional array.
+ 1
Make no mistake, you can do this with the tkinter library, I will give an example
İmport tkinter as tk
Image = PhotoImage(filename = [Your Image here])
Lbl = Label (width=490, img=image)
If Python 3, you can (import tkinter as tk ) use it
And if Python 2,you can (import Tkinter as tk) use is
+ 1
I can't imagine
0
Abhay did you mean to say "it's nothing more than a 2 dimensional array"?
0
Abhay then image[0,0] would return only the address of a 1-D array right? I think I don't get it
0
Good luck. It was my duty
0
What is error ?