I am trying to make a script that scans an image, and then tells me what color pixels are in it, but when I print the pixels color value, it prints the same color value for every time it occurs in the image.
I have figured out to sort the values sort they are besides each other.
from PIL import Image
img = Image.open('images/image.png')
print(img.size)
print("pixels")
pix = img.load()
pix_val = list(img.getdata())
pix_val.sort()
print(pix_val)
It prints the color values for each time they occur in the image, so I get a very long print.
You can get the distribution of unique pixels using the following code:
from collections import Counter
Counter(pix_val)
If you only need to know which are the unique colours, just run the following code as Adrian told you on the comments.
set(pix_val)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With