def create_image_footprint(image, refwcs, border=0.):
    """ Create the footprint of the image in the reference WCS frame.

    Parameters
    ----------
    image : `astropy.io.fits.HDUList` or str
        Image to extract sources for matching to
        the external astrometric catalog.

    refwcs : `stwcs.wcsutil.HSTWCS`
        Reference WCS for coordinate frame of image.

    border : float
        Buffer (in arcseconds) around edge of image to exclude astrometric
        sources.

    """
    # Interpret input image to generate initial source catalog and WCS
    if isinstance(image, str):
        image = pf.open(image)
    numSci = countExtn(image, extname='SCI')
    ref_x = refwcs._naxis1
    ref_y = refwcs._naxis2
    # convert border value into pixels
    border_pixels = int(border / refwcs.pscale)

    mask_arr = np.zeros((ref_y, ref_x), dtype=int)

    for chip in range(numSci):
        chip += 1
        # Build arrays of pixel positions for all edges of chip
        chip_y, chip_x = image['sci', chip].data.shape
        chipwcs = wcsutil.HSTWCS(image, ext=('sci', chip))
        xpix = np.arange(chip_x) + 1
        ypix = np.arange(chip_y) + 1
        edge_x = np.hstack([[1] * chip_y, xpix, [chip_x] * chip_y, xpix])
        edge_y = np.hstack([ypix, [1] * chip_x, ypix, [chip_y] * chip_x])
        edge_ra, edge_dec = chipwcs.all_pix2world(edge_x, edge_y, 1)
        edge_x_out, edge_y_out = refwcs.all_world2pix(edge_ra, edge_dec, 0)
        edge_x_out = np.clip(edge_x_out.astype(np.int32), 0, ref_x - 1)
        edge_y_out = np.clip(edge_y_out.astype(np.int32), 0, ref_y - 1)
        mask_arr[edge_y_out, edge_x_out] = 1

    # Fill in outline of each chip
    mask_arr = ndimage.binary_fill_holes(ndimage.binary_dilation(mask_arr, iterations=2))

    if border > 0.:
        mask_arr = ndimage.binary_erosion(mask_arr, iterations=border_pixels)

    return mask_arr
Create the footprint of the image in the reference WCS frame.

    Parameters
    ----------
    image : `astropy.io.fits.HDUList` or str
        Image to extract sources for matching to
        the external astrometric catalog.

    refwcs : `stwcs.wcsutil.HSTWCS`
        Reference WCS for coordinate frame of image.

    border : float
        Buffer (in arcseconds) around edge of image to exclude astrometric
        sources.