return pageimg[min(c[0] for c in coords):max(c[0] for c in coords),
min(c[1] for c in coords):max(c[1] for c in coords)]
rr, cc = polygon(coords[:, 0], coords[:, 1], pageimg.shape)
offset = (min([x[0] for x in coords]), min([x[1] for x in coords]))
box = np.ones(
(max([x[0] for x in coords]) - offset[0],
max([x[1] for x in coords]) - offset[1],
) + ((pageimg.shape[-1],) if len(pageimg.shape) == 3 else ()),