def extract_patch(im, patch_size):
    """Extract a center cropped patch of size 'patch_size' (2-element tuple).

    :param im: input image
    :type im: PIL image object
    :param patch_size: size of patch
    :type patch_size: tuple, array, or similar
    :return: center-cropped patch
    :rtype: PIL image object
    """
    left = (im.size[0] - patch_size[0]) // 2
    top = (im.size[1] - patch_size[1]) / 2
    right = left + patch_size[0]
    bottom = top + patch_size[1]
    return im.crop([left, top, right, bottom])
