+ 3

How to access individual pixels of image in Python. Pls help

2nd Oct 2021, 10:06 PM
🌼Faith🌼
🌼Faith🌼 - avatar
11 Antworten
+ 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])
2nd Oct 2021, 10:42 PM
Abhay
Abhay - avatar
+ 2
Alternatively you can take a look at the pillow module. https://ehmatthes.github.io/pcc_2e/beyond_pcc/pillow/
2nd Oct 2021, 10:51 PM
Simon Sauter
Simon Sauter - avatar
+ 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)
3rd Oct 2021, 9:32 AM
Abhay
Abhay - avatar
+ 2
Thanks for your responses. They were really helpful
3rd Oct 2021, 2:31 PM
🌼Faith🌼
🌼Faith🌼 - avatar
+ 1
Rishi 3 dimensional array.
3rd Oct 2021, 8:17 AM
Abhay
Abhay - avatar
+ 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
3rd Oct 2021, 2:21 PM
Aydin
Aydin - avatar
+ 1
I can't imagine
3rd Oct 2021, 6:17 PM
INST・RIC卄
0
Abhay did you mean to say "it's nothing more than a 2 dimensional array"?
3rd Oct 2021, 2:19 AM
Rishi
Rishi - avatar
0
Abhay then image[0,0] would return only the address of a 1-D array right? I think I don't get it
3rd Oct 2021, 8:23 AM
Rishi
Rishi - avatar
0
Good luck. It was my duty
3rd Oct 2021, 2:33 PM
Aydin
Aydin - avatar
0
What is error ?
3rd Oct 2021, 6:30 PM
Aydin
Aydin - avatar