I am new to python and would like to be pointed in the next direction. I am using PIL. Done a fair bit of research, and I’m still stuck!
I need to get the rgb of each pixel starting at 0,0 and going along each row all the way down the y coordinate. Its a bmp and only black and white, but I only want python to print pixels which are between 10,10,10 and 0,0,0. Could someone offer me some wisdom?
If you’re sure that
r==g==bfor all pixels, then this should work:If it is NOT guaranteed that
r==g==bfor some reason, adjust the conditions as necessary. If you want an average of 10, for example, you could change the condition to something likeAlso note that for greyscale-format files (as opposed to greyscale images in a color file format)
im.getdata()will return simply the grey level as a single value. So for a 2×2 image ofrgb(15, 15, 15),list(data)will output[4, 4, 4, 4]instead of[(4, 4, 4), (4, 4, 4), (4, 4, 4), (4, 4, 4)]. In this case, when analyzing, refer just toiinstead ofi[0]