def shift_int(template, image, y, x):
    """
    Quickly shift an image with respect to a template and return a parameter
    that is minimized when the images are well aligned. The sum of squres is
    not applicable here because that favors reducing the number of pixels
    in the image, which is the effect of applying a large shift.

    Arguments:
    template -- The image to match
    image -- The input image that is shifted
    y -- Integer offset along axis 0
    x -- Integer offset along axis 1
    """
    y, x = int(y), int(x)
    h, w = image.shape

    shifted_template = template[max(0, y):min(h, h+y), max(0, x):min(w, w+x)]
    shifted_image = image[max(0, -y):min(h, h-y), max(0, -x):min(w, w-x)]

    output = 0.0
    for row in range(shifted_image.shape[0]):
        for col in range(shifted_image.shape[1]):
            output += (shifted_template[row, col] - shifted_image[row, col])**2

    return output/shifted_image.size