Example #1
0
def filter_lowpass(im, cutoffFrequency, order=1, filterShape=ipcv.IPCV_IDEAL):
    """
    Function to generate a lowpass filter for the shape of a given image

    Args:
        im (array): source image, needed for the shape of the filter
        cutoffFrequency (int): the frequency at which the filter stops
        order (optional[int]): the order of the power for non-ideal filters
        filterShape (optional[int]): Frequency filter shapes,
            defined in constants.py, defaults to ideal filter

    Return:
        the filter for the image, as numpy.float64 data types
    """

    distanceArray = ipcv.filter_distance(im).astype(np.float64)
    filterFunction = {
        ipcv.IPCV_IDEAL: ideal_lowpass,
        ipcv.IPCV_BUTTERWORTH: butterworth_lowpass,
        ipcv.IPCV_GAUSSIAN: gaussian_lowpass
    }

    return filterFunction[filterShape](distanceArray, cutoffFrequency, order)
def filter_highpass(im, cutoffFrequency, order=1, filterShape=ipcv.IPCV_IDEAL):
    """
    Function to generate a highpass filter for the shape of a given image

    Args:
        im (array): source image, needed for the shape of the filter
        cutoffFrequency (int): the frequency at which the filter stops
        order (optional[int]): the order of the power for non-ideal filters
        filterShape (optional[int]): Frequency filter shapes,
            defined in constants.py, defaults to ideal filter

    Return:
        the filter for the image, as numpy.float64 data types
    """

    distanceArray = ipcv.filter_distance(im).astype(np.float64)
    filterFunction = {
        ipcv.IPCV_IDEAL : ipcv.ideal_lowpass,
        ipcv.IPCV_BUTTERWORTH : ipcv.butterworth_lowpass,
        ipcv.IPCV_GAUSSIAN : ipcv.gaussian_lowpass
    }

    return 1-filterFunction[filterShape](distanceArray, cutoffFrequency, order)
def filter_bandpass(im, radialCenter, bandwidth, order=1, filterShape=ipcv.IPCV_IDEAL):
    """
    Function to generate a bandpass filter for the shape of a given image

    Args:
        im (array): source image, needed for the shape of the filter
        radialCenter (int): the frequency at which the filter stops
        brandwidth (int): the width of the band
        order (optional[int]): the order of the power for non-ideal filters
        filterShape (optional[int]): Frequency filter shapes,
            defined in constants.py, defaults to ideal filter

    Return:
        the filter for the image, as numpy.float64 data types
    """

    distanceArray = ipcv.filter_distance(im).astype(np.float64)
    filterFunction = {
        ipcv.IPCV_IDEAL : ipcv.ideal_bandreject,
        ipcv.IPCV_BUTTERWORTH : ipcv.butterworth_bandreject,
        ipcv.IPCV_GAUSSIAN : ipcv.gaussian_bandreject
    }

    return 1-filterFunction[filterShape](distanceArray, radialCenter, bandwidth, order)