How PIL imports image data: a useful reference for checking stellar.py intensitySAAW() and tools.py converter()

How our image data imported via PIL and converted to numpy array is stored

Our test image, img_2617.tif, is 1810x606 (WxH). Each element in the big list is a row, of which there are 606. Each element in the row list is a column list. Each column list has 1810 columns. Each element in the column list is a 3-element list. This three element list contains the R,G,B raw image data.

@brunston

In [2]:
import numpy as np
from PIL import Image

In [3]:
img = Image.open("IMG_2617.tif")
img_data = np.array(img)
img_data


Out[3]:
array([[[1, 0, 0],
        [1, 0, 1],
        [1, 0, 1],
        ..., 
        [1, 0, 0],
        [3, 2, 2],
        [0, 0, 0]],

       [[1, 0, 1],
        [0, 0, 0],
        [1, 1, 1],
        ..., 
        [1, 0, 1],
        [1, 1, 1],
        [0, 0, 0]],

       [[0, 0, 0],
        [1, 0, 0],
        [1, 0, 1],
        ..., 
        [1, 0, 0],
        [0, 0, 0],
        [1, 1, 1]],

       ..., 
       [[1, 0, 1],
        [0, 0, 0],
        [0, 0, 0],
        ..., 
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[2, 1, 2],
        [1, 1, 1],
        [0, 0, 0],
        ..., 
        [1, 0, 0],
        [1, 1, 1],
        [0, 0, 0]],

       [[1, 0, 0],
        [1, 0, 0],
        [1, 1, 1],
        ..., 
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]]], dtype=uint8)

In [4]:
len(img_data)


Out[4]:
606

In [5]:
len(img_data[0])


Out[5]:
1810

In [6]:
len(img_data[0][1])


Out[6]:
3

In [7]:
np.fliplr(img_data)


Out[7]:
array([[[0, 0, 0],
        [3, 2, 2],
        [1, 0, 0],
        ..., 
        [1, 0, 1],
        [1, 0, 1],
        [1, 0, 0]],

       [[0, 0, 0],
        [1, 1, 1],
        [1, 0, 1],
        ..., 
        [1, 1, 1],
        [0, 0, 0],
        [1, 0, 1]],

       [[1, 1, 1],
        [0, 0, 0],
        [1, 0, 0],
        ..., 
        [1, 0, 1],
        [1, 0, 0],
        [0, 0, 0]],

       ..., 
       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ..., 
        [0, 0, 0],
        [0, 0, 0],
        [1, 0, 1]],

       [[0, 0, 0],
        [1, 1, 1],
        [1, 0, 0],
        ..., 
        [0, 0, 0],
        [1, 1, 1],
        [2, 1, 2]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ..., 
        [1, 1, 1],
        [1, 0, 0],
        [1, 0, 0]]], dtype=uint8)

In [ ]: