In [1]:
from PIL import Image

FILENAME = "Huffman-steps"
EXT = "png"

In [2]:
%matplotlib inline

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np

def show(pil_image):
    plt.figure()
    fig = plt.imshow(np.asarray(pil_image))
    plt.axis('off')

In [3]:
image = Image.open("{}.{}".format(FILENAME, EXT))
show(image) # image.show()



In [4]:
width, height = image.size
print("Width: {}\nHeight: {}".format(width, height))


Width: 657
Height: 444

In [5]:
# (left, upper, right, lower) coordinates
col_1 = 0
col_2 = width // 2
col_3 = width
col_gap = 50
row_1 = 0
row_2 = 105
row_3 = 250
parts_heights = [30, 65, 65, 110, height - row_3 - 40, height - row_3]
BOXES = [
    (
        col_1, 
        row_1, 
        col_2 - col_gap, 
        row_1 + parts_heights[0]),
    (
        col_2 + col_gap, 
        row_1, 
        col_3, 
        row_1 + parts_heights[1]),
    (
        col_1, 
        row_2, 
        col_2 - col_gap, 
        row_2 + parts_heights[2]),
    (
        col_2 + col_gap, 
        row_2, 
        col_3, 
        row_2 + parts_heights[3]),
    (
        col_1, 
        row_3, 
        col_2 - col_gap, 
        row_3 + parts_heights[4]),
    (
        col_2 + col_gap, 
        row_3, 
        col_3, 
        row_3 + parts_heights[5])
]
for i in range(len(BOXES)):
    box = BOXES[i]
    image_crop = image.crop(box)
    show(image_crop)
    CROP_NAME = str(i + 1)
    image_crop.save("{}_{}.{}".format(FILENAME, CROP_NAME, EXT), EXT)