def filter_notchpass(img, notchCenter, notchRadius, order=1, filterShape=ipcv.IPCV_IDEAL): """ :purpose: generates a notch reject filter :inputs: img [np.ndarray] '--> img to generate filter for notchCenter [tuple] '--> notch offset notchRadius '--> radius of the notch filterShape '--> type of filter to apply :return: frequency filter [np.ndarray] """ notchReject = ipcv.filter_notchreject(img, notchCenter, notchRadius, order, filterShape) notchPass = 1 - notchReject return notchPass
def filter_notchpass(im, notchCenter, notchRadius, order=1, filterShape=ipcv.IPCV_IDEAL): notchReject = ipcv.filter_notchreject(im, notchCenter, notchRadius, order, filterShape) notchPass = 1 - notchReject return notchPass
def filter_notchpass(im, notchCenter, notchRadius, order=1, filterShape=ipcv.IPCV_IDEAL): ''' title:: filter_notchpass description:: This method creates a notchpass filter to be applied to the centered fourier transform of the input image. It calls the notchreject method in ipcv and subtracts the resulting filter from 1, thereby only letting through the notch frequencies. attributes:: im Input image of tpye numpy nd array, used to get the dimensions for the frequency filter. notchCenter List of tuples with coordinates (u,v) corresponding to frequencies in the fourier transform to be rejected. notchRadius The size of the notch to be created at each (u,v) coordinate. 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 specified notch sizes and locations. Binary mask. BUTTERWORTH Gaussian-like shaped filter that can be tuned based on the order parameter. GAUSSIAN Gaussian-shaped filter. returns:: notchpass filter - numpy array with the same dimensions as the input image. author:: Victoria Scholl ''' notchPassFilter = 1 - ipcv.filter_notchreject(im, notchCenter, notchRadius, order, filterShape) return notchPassFilter.astype(numpy.float64)
def filter_notchpass(im, notchCenter, notchRadius, order=1, filterShape=ipcv.IPCV_IDEAL): """ Title: filter_notchpass Description: Creates a notch filter for given image and parameters Attributes: im - 2D ndarray signal to provide shape of filter notchCenter - center of the frequency to be allowed notchRadius - width of notch 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(notchCenter) != tuple or notchCenter[0] < 0 or type(notchCenter[0]) != int \ or notchCenter[1] <0 or type(notchCenter[1]) != int: raise ValueError("Given notchCenter must be tuple of positive integers.") if type(notchRadius) != int or notchRadius < 0: raise ValueError("Given notch radius 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_notchreject(im,notchCenter,notchRadius,order,filterShape) return(H)
if __name__ == '__main__': 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_notchreject(im, (50,50), 32, 1, filterShape=ipcv.IPCV_IDEAL) frequencyFilter = ipcv.filter_notchreject(im, (50,50), 32, 1, filterShape=ipcv.IPCV_BUTTERWORTH) frequencyFilter = ipcv.filter_notchreject(im, (50,50), 32, 1, filterShape=ipcv.IPCV_GAUSSIAN) # Create a 3D plot and image visualization of the frequency domain filter rows = im.shape[0] columns = im.shape[1]
import cv2 import ipcv import numpy import matplotlib.pyplot import matplotlib.cm import mpl_toolkits.mplot3d filename = '/cis/faculty/cnspci/public_html/courses/common/images/lenna_color.tif' filename = 'lena_periodic.jpg' im = cv2.imread(filename) notchCenter = [(32,0)] notchRadius = [3] frequencyFilter = ipcv.filter_notchreject(im, notchCenter, notchRadius, filterShape=ipcv.IPCV_IDEAL) frequencyFilter = ipcv.filter_notchreject(im, notchCenter, notchRadius, order=1, filterShape=ipcv.IPCV_BUTTERWORTH) #frequencyFilter = ipcv.filter_notchreject(im, # notchCenter, # notchRadius, # 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)
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_notchreject(im, #(32,32), #10, #filterShape=ipcv.IPCV_IDEAL) frequencyFilter = ipcv.filter_notchreject(im, (32,32), 10, order=2, filterShape=ipcv.IPCV_BUTTERWORTH) #frequencyFilter = ipcv.filter_notchreject(im, #(32,32), #10, #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))