Getting list of pixel values from PIL

前端 未结 9 1139
感动是毒
感动是毒 2020-11-27 15:07

Guys, I\'m looking for a bit of assistance. I\'m a newbie programmer and one of the problems I\'m having at the minute is trying to convert a black & white .jpg

9条回答
  •  清酒与你
    2020-11-27 15:58

    Not PIL, but scipy.misc.imread might still be interesting:

    import scipy.misc
    im = scipy.misc.imread('um_000000.png', flatten=False, mode='RGB')
    print(im.shape)
    

    gives

    (480, 640, 3)
    

    so it is (height, width, channels). So you can iterate over it by

    for y in range(im.shape[0]):
        for x in range(im.shape[1]):
            color = tuple(im[y][x])
            r, g, b = color
    

提交回复
热议问题