def crop(img, w, h):
    """
    Extract part of size w x h from center of the given image
    """
    w_, h_ = img.shape[0:2]
    w_off, h_off = (w_ - w) // 2, (h_ - h) // 2
    assert w_ >= w and h_ >= h, "cannot crop from {}x{} to {}x{}".format(w_, h_, w, h)

    return img[w_off:w_off + w, h_off:h_off + h]