Convert an image to 2D array in python

前端 未结 3 894
独厮守ぢ
独厮守ぢ 2021-02-07 16:24

I want to convert an image to 2D array with 5 columns where each row is of the form [r, g, b, x, y]. x, y is the position of the pixel and r,g,b are the pixel value

3条回答
  •  我寻月下人不归
    2021-02-07 16:40

    I used "+" to combine two tuple, and use .append() to make "data" list.No need to use Numpy here.

    row,col = im.size
    data=[] #r,g,b,i,j
    pixels=im.load()
    for i in range(row):
      for j in range(col):
        data.append(pixels[i,j]+(i,j))
    

提交回复
热议问题