def filter_bandpass(img, radialCenter, bandwidth, order=1, filterShape=ipcv.IPCV_IDEAL): """ :purpose: generates a bandpass filter :inputs: img [np.ndarray] '--> img to generate filter for radialCenter [np.ndarray] '--> size of bandpass bandwidth [np.ndarray] '--> size of bandpass order [int] '--> order for butterworth filter filterShape [int] '--> type of filter to apply :return: frequency filter [np.ndarray] """ bandReject = ipcv.filter_bandreject(img, radialCenter, bandwidth, order, filterShape) bandPass = 1 - bandReject return bandPass
def filter_bandpass(im, radialCenter, bandwidth, order=1, filterShape=ipcv.IPCV_IDEAL): bandPassFilter = 1 - ipcv.filter_bandreject(im, radialCenter, bandwidth, order, filterShape) return bandPassFilter.astype(np.float64)
def filter_bandpass(im, radialCenter, bandwidth, order=1, filterShape=ipcv.IPCV_IDEAL): ''' title:: filter_bandpass description:: This method creates a bandpass filter to be applied to the centered fourier transform of the input image. It calls the bandreject method in ipcv and subtracts the resulting filter from 1, thereby only letting a band of frequencies from the input image pass through. attributes:: im Input image of tpye numpy nd array, used to get the dimensions for the frequency filter. radialCenter Distance (integer) from the center of the fourier transform at which the frequency range begins. bandwidth Thickness of the band of frequencies to be passed, measured outward from the radialCenter distance. order Integer value that influences the shape of the butterworth filter. The higher the order, the more the butterworth filter resembles an ideal filter. filterShape Options for the shape of the filter, specified in the constants.py file in the ipcv directory. The different shapes will attenuate the higher frequencies differently. IDEAL Ideal shaped filter STRICTLY allows ALL frequencies within the range to be passed. Binary mask. BUTTERWORTH Gaussian-like shaped filter that can be tuned based on the order parameter. GAUSSIAN Gaussian-shaped filter. returns:: bandpass filter - numpy array with the same dimensions as the input image. It looks like a donut! Allows frequencies to pass within the specified range and attenuates outsiders. author:: Victoria Scholl ''' bandPassFilter = 1 - ipcv.filter_bandreject(im, radialCenter, bandwidth, order, filterShape) return bandPassFilter.astype(numpy.float64)
def filter_bandpass(im, radialCenter, bandwidth, order=1, filterShape=ipcv.IPCV_IDEAL): """ Title: filter_bandpass Description: Creates a bandpass filter for given image and parameters Attributes: im - 2D ndarray signal to provide shape of filter radialCenter - radial center of the band pass annulus bandwidth - width of band order - order of the filter (applicable only to Butterworth) filterShape - shape of frequency filter: - 0 = Ideal - 1 = Butterworth - 2 = Gaussian Author: Molly Hill, [email protected] """ #error-checking if type(im) != np.ndarray: raise TypeError("Source image must be ndarray.") if type(radialCenter) != int or radialCenter < 0: raise ValueError("Given radialCenter must be positive integer.") if type(bandwidth) != int or bandwidth < 0: raise ValueError("Given bandwidth must be positive integer.") if type(order) != int or order < 0: raise ValueError("Given order must be positive integer.") if type(filterShape) != int or filterShape < 0 or filterShape > 2: raise ValueError("Filter shape option limited to 0, 1, or 2.") H = 1 - ipcv.filter_bandreject(im, radialCenter, bandwidth, order, filterShape) return (H)
import matplotlib.pyplot import matplotlib.cm import mpl_toolkits.mplot3d import os.path home = os.path.expanduser('~') filename = home + os.path.sep + 'src/python/examples/data/lenna.tif' im = cv2.imread(filename) # frequencyFilter = ipcv.filter_bandreject(im, # 32, # 15, # filterShape=ipcv.IPCV_IDEAL) frequencyFilter = ipcv.filter_bandreject(im, 100, 15, 1, filterShape=ipcv.IPCV_BUTTERWORTH) # frequencyFilter = ipcv.filter_bandreject(im, # 32, # 15, # filterShape=ipcv.IPCV_GAUSSIAN) # Create a 3D plot and image visualization of the frequency domain filter rows = im.shape[0] columns = im.shape[1] u = numpy.arange(-columns/2, columns/2, 1) v = numpy.arange(-rows/2, rows/2, 1) u, v = numpy.meshgrid(u, v) figure = matplotlib.pyplot.figure('Frequency Domain Filter', (14, 6))
home = os.path.expanduser('~') filename = home + os.path.sep + 'src/python/examples/data/lenna.tif' im = cv2.imread(filename) #frequencyFilter = ipcv.filter_bandreject(im, #32, #15, #filterShape=ipcv.IPCV_IDEAL) #frequencyFilter = ipcv.filter_bandreject(im, #32, #15, #order=1, #filterShape=ipcv.IPCV_BUTTERWORTH) frequencyFilter = ipcv.filter_bandreject(im, 32, 15, filterShape=ipcv.IPCV_GAUSSIAN) # Create a 3D plot and image visualization of the frequency domain filter rows = im.shape[0] columns = im.shape[1] u = numpy.arange(-columns / 2, columns / 2, 1) v = numpy.arange(-rows / 2, rows / 2, 1) u, v = numpy.meshgrid(u, v) figure = matplotlib.pyplot.figure('Frequency Domain Filter', (14, 6)) p = figure.add_subplot(1, 2, 1, projection='3d') p.set_xlabel('u') p.set_xlim3d(-columns / 2, columns / 2) p.set_ylabel('v') p.set_ylim3d(-rows / 2, rows / 2)
import cv2 import ipcv import numpy import matplotlib.pyplot import matplotlib.cm import mpl_toolkits.mplot3d import os.path home = os.path.expanduser('~') filename = home + os.path.sep + 'src/python/examples/data/lenna.tif' im = cv2.imread(filename) frequencyFilter = ipcv.filter_bandreject(im, 32, 15, order=2, filterShape=ipcv.IPCV_BUTTERWORTH) frequencyFilter = ipcv.filter_bandreject(im, 32, 15, filterShape=ipcv.IPCV_GAUSSIAN) frequencyFilter = ipcv.filter_bandreject(im, 32, 15, filterShape=ipcv.IPCV_IDEAL) # Create a 3D plot and image visualization of the frequency domain filter rows = im.shape[0] columns = im.shape[1] u = numpy.arange(-columns/2, columns/2, 1)