In [4]:
import numpy as np
from PIL import Image, ImageOps, ImageStat
In [3]:
img = Image.open("../../home/media/poker/4h.png")
img
Out[3]:
You can use either numpy.asarray
or numpy.array
to convert an image to a numpy array.
The resulting numpy array is a 3-dimensional array
with the third/last dimention being the 3 channels (RGB)
no matter the format of the image.
In [4]:
np.asarray(img)
Out[4]:
In [9]:
arr = np.array(img)
arr
Out[9]:
The resulting numpy array has the dimension (54, 37, 3) since the image has 3 channels (RGB).
In [10]:
arr.shape
Out[10]:
Points in the middle of th red heart has large values in the first (R) channel, which is as expected.
In [14]:
arr[8, 8, :]
Out[14]:
In [13]:
arr[9, 9, :]
Out[13]:
In [15]:
arr[10, 10, :]
Out[15]: