<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def reflect_image(image, axis=None, tx=None, metric='mattes'):
 """ Reflect an image along an axis ANTsR function: `reflectImage` Arguments --------- image : ANTsImage image to reflect axis : integer (optional) which dimension to reflect across, numbered from 0 to imageDimension-1 tx : string (optional) transformation type to estimate after reflection metric : string similarity metric for image registration. see antsRegistration. Returns ------- ANTsImage Example ------- """

    if axis is None:
        axis = image.dimension - 1

    if (axis > image.dimension) or (axis < 0):
        axis = image.dimension - 1

    rflct = mktemp(suffix='.mat')

    libfn = utils.get_lib_fn('reflectionMatrix%s'%image._libsuffix)
    libfn(image.pointer, axis, rflct)

    if tx is not None:
        rfi = registration(image, image, type_of_transform=tx,
                            syn_metric=metric, outprefix=mktemp(),
                            initial_transform=rflct)
        return rfi
    else:
        return apply_transforms(image, image, rflct)