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)
In [4]:
im_0 = im[:, :100]
im_1 = im[:, 100:]
In [5]:
print(im_0.shape)
In [6]:
print(im_1.shape)
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)
In [10]:
print(im_1.shape)
In [11]:
im_0, im_1, im_2 = np.hsplit(im, [100, 150])
In [12]:
print(im_0.shape)
In [13]:
print(im_1.shape)
In [14]:
print(im_2.shape)
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)
In [18]:
print(im_1.shape)
In [19]:
print(im_2.shape)