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

In [2]:
im = np.array(Image.open('data/src/lena_square.png').resize((256, 256)))

In [3]:
print(im.shape)


(256, 256, 3)

In [4]:
im_0 = im[:, :100]
im_1 = im[:, 100:]

In [5]:
print(im_0.shape)


(256, 100, 3)

In [6]:
print(im_1.shape)


(256, 156, 3)

In [7]:
Image.fromarray(im_0).save('data/dst/lena_numpy_split_0.jpg')
Image.fromarray(im_1).save('data/dst/lena_numpy_split_1.jpg')

In [8]:
im_0, im_1 = np.hsplit(im, 2)

In [9]:
print(im_0.shape)


(256, 128, 3)

In [10]:
print(im_1.shape)


(256, 128, 3)

In [11]:
im_0, im_1, im_2 = np.hsplit(im, [100, 150])

In [12]:
print(im_0.shape)


(256, 100, 3)

In [13]:
print(im_1.shape)


(256, 50, 3)

In [14]:
print(im_2.shape)


(256, 106, 3)

In [15]:
# im_0, im_1, im_2 = np.hsplit(im, 3)
# ValueError: array split does not result in an equal division

In [16]:
im_0, im_1, im_2 = np.array_split(im, 3, axis=1)

In [17]:
print(im_0.shape)


(256, 86, 3)

In [18]:
print(im_1.shape)


(256, 85, 3)

In [19]:
print(im_2.shape)


(256, 85, 3)