def get_merge_indices(cen, imglen, ks_h, ker_shp):
    """Helper function that returns indices for merging stencil with base
    image, including edge case handling.  x and y are identical, so code is
    axis-neutral.
    Assumes INTEGER values for all inputs!
    """

    left = cen - ks_h
    right = cen + ks_h + 1

    # Handle edge cases.  If left side of stencil is beyond the left end of
    # the image, for example, crop stencil and shift image index to lefthand
    # side.
    if left < 0:
        img_l = 0
        g_l = -left
    else:
        img_l = left
        g_l = 0
    if right > imglen:
        img_r = imglen
        g_r = ker_shp - (right - imglen)
    else:
        img_r = right
        g_r = ker_shp

    return [img_l, img_r, g_l, g_r]