<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def fftmorphology(im, strel, mode='opening'):
 r""" Perform morphological operations on binary images using fft approach for improved performance Parameters im : nd-array The binary image on which to perform the morphological operation strel : nd-array The structuring element to use. Must have the same dims as ``im``. mode : string The type of operation to perform. Options are 'dilation', 'erosion', 'opening' and 'closing'. Returns ------- image : ND-array A copy of the image with the specified moropholgical operation applied using the fft-based methods available in scipy.fftconvolve. Notes ----- This function uses ``scipy.signal.fftconvolve`` which *can* be more than 10x faster than the standard binary morphology operation in ``scipy.ndimage``. This speed up may not always be realized, depending on the scipy distribution used. Examples -------- Check that erosion, dilation, opening, and closing are all the same as the ``scipy.ndimage`` functions: True True True True """


    def erode(im, strel):
        t = fftconvolve(im, strel, mode='same') > (strel.sum() - 0.1)
        return t

    def dilate(im, strel):
        t = fftconvolve(im, strel, mode='same') > 0.1
        return t

    if im.ndim != im.squeeze().ndim:
        warnings.warn('Input image conains a singleton axis:' + str(im.shape) +
                      ' Reduce dimensionality with np.squeeze(im) to avoid' +
                      ' unexpected behavior.')

    # Perform erosion and dilation
    # The array must be padded with 0's so it works correctly at edges
    temp = sp.pad(array=im, pad_width=1, mode='constant', constant_values=0)
    if mode.startswith('ero'):
        temp = erode(temp, strel)
    if mode.startswith('dila'):
        temp = dilate(temp, strel)

    # Remove padding from resulting image
    if im.ndim == 2:
        result = temp[1:-1, 1:-1]
    elif im.ndim == 3:
        result = temp[1:-1, 1:-1, 1:-1]

    # Perform opening and closing
    if mode.startswith('open'):
        temp = fftmorphology(im=im, strel=strel, mode='erosion')
        result = fftmorphology(im=temp, strel=strel, mode='dilation')
    if mode.startswith('clos'):
        temp = fftmorphology(im=im, strel=strel, mode='dilation')
        result = fftmorphology(im=temp, strel=strel, mode='erosion')

    return result