Python - get white pixels of image -


i'm go image filename list of coordinates of white pixels in image.

i know involves pil. have tried using image.load() doesn't because output not indexable (to use in for loop).

you can dump image numpy array , manipulate pixel values way.

from pil import image import numpy np im=image.open("someimage.png") pixels=np.asarray(im.getdata()) npixels,bpp=pixels.shape 

this give array dimensions depend on how many bands have per pixel (bpp above) , number of rows times number of columns in image -- shape give size of resulting array. once have pixel values, ought straightforward filter out values 255

to convert numpy array image use:

im=image.fromarray(pixels) 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -