import copy


def cut_edges(image, numPix):
    """
    cuts out the edges of a 2d image and returns re-sized image to numPix
    center is well defined for odd pixel sizes.
    :param image: 2d numpy array
    :param numPix: square size of cut out image
    :return: cutout image with size numPix
    """
    nx, ny = image.shape
    if nx < numPix or ny < numPix:
        raise ValueError('image can not be resized, in routine cut_edges with image shape (%s %s) '
                         'and desired new shape (%s %s)' % (nx, ny, numPix, numPix))
    if (nx % 2 == 0 and ny % 2 == 1) or (nx % 2 == 1 and ny % 2 == 0):
        raise ValueError('image with odd and even axis (%s %s) not supported for re-sizeing' % (nx, ny))
    if (nx % 2 == 0 and numPix % 2 == 1) or (nx % 2 == 1 and numPix % 2 == 0):
        raise ValueError('image can only be re-sized from even to even or odd to odd number.')

    x_min = int((nx - numPix) / 2)
    y_min = int((ny - numPix) / 2)
    x_max = nx - x_min
    y_max = ny - y_min
    resized = image[x_min:x_max, y_min:y_max]
    return copy.deepcopy(resized)