def filter_highpass(im, cutoffFrequency, order=1, filterShape=ipcv.IPCV_IDEAL):
	"""
	Title:
		filter_highpass
	Description:
		Creates a highpass filter for given image and parameters
	Attributes:
		im - 2D ndarray signal to provide shape of filter
		cutoffFrequency - allow frequencies above this threshold
		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(cutoffFrequency) != int or cutoffFrequency < 0:
		raise ValueError("Given cutoff frequency 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_lowpass(im,cutoffFrequency,order,filterShape)

	return(H)
Beispiel #2
0
def filter_highpass(img,
                    cutoffFrequency,
                    order=1,
                    filterShape=ipcv.IPCV_IDEAL):
    """
	:purpose:
		generates a highpass filter
	:inputs:
		img [np.ndarray]
			'--> img to generate filter for
		cutoffFrequency [np.ndarray]
			'--> notch offset
		order
			'--> order for butterworth filter
		filterShape
			'--> type of filter to apply
	:return:
		frequency filter [np.ndarray]

	"""
    try:
        lowPass = ipcv.filter_lowpass(img, cutoffFrequency, order, filterShape)
        highPass = 1 - lowPass
        return highPass

    except Exception as e:
        ipcv.debug(e)
Beispiel #3
0
def filter_highpass(im, cutoffFrequency, order=1, filterShape=ipcv.IPCV_IDEAL):
   '''
   title::
      filter_highpass

   description::
      This method creates a highpass filter to be applied to the 
      centered fourier transform of the input image.
      It calls the lowpass method in ipcv and subtracts the resulting 
      filter from 1. 

   attributes::
      im
         Input image of tpye numpy nd array, used to get the dimensions for
         the frequency filter.
      cutoffFrequency
         Frequency of type integer above which to attentuate higher frequencies
         (frequencies lower than the cutoff value will be preserved). 
      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 greater than
               the cutoffFrequency to pass. Binary mask. 
            BUTTERWORTH
               Gaussian-like shaped filter that can be tuned based on the order
               parameter. 
            GAUSSIAN
               Gaussian-shaped filter. 
   returns::
      highpass filter - numpy array with the same dimensions as the input image

   author::
      Victoria Scholl

   '''

   highPass = 1 - ipcv.filter_lowpass(im, cutoffFrequency, order, filterShape)

   return highPass.astype(numpy.float64)
Beispiel #4
0

if __name__ == '__main__':

   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'
   im = cv2.imread(filename)

   frequencyFilter = ipcv.filter_lowpass(im,
                                         16,
                                         filterShape=ipcv.IPCV_IDEAL)
   frequencyFilter = ipcv.filter_lowpass(im,
                                         16,
                                         order=1,
                                         filterShape=ipcv.IPCV_BUTTERWORTH)
   frequencyFilter = ipcv.filter_lowpass(im,
                                         16,
                                         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)
Beispiel #5
0
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_lowpass(im, 16, filterShape=ipcv.IPCV_IDEAL)
    frequencyFilter = ipcv.filter_lowpass(im,
                                          16,
                                          order=1,
                                          filterShape=ipcv.IPCV_BUTTERWORTH)
    frequencyFilter = ipcv.filter_lowpass(im,
                                          16,
                                          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)
Beispiel #6
0
if __name__ == '__main__':

    import cv2
    import ipcv
    import numpy
    import os.path
    import time

    home = os.path.expanduser('~')
    filename = home + os.path.sep + 'src/python/examples/data/lenna.tif'
    filename = home + os.path.sep + 'src/python/examples/data/giza.jpg'

    im = cv2.imread(filename)

    frequencyFilter = ipcv.filter_lowpass(im,
                                          16,
                                          filterShape=ipcv.IPCV_GAUSSIAN)

    startTime = time.clock()
    offset = 0
    filteredImage = ipcv.frequency_filter(im, frequencyFilter, delta=offset)
    filteredImage = numpy.abs(filteredImage)
    filteredImage = filteredImage.astype(dtype=numpy.uint8)
    elapsedTime = time.clock() - startTime
    print('Elapsed time (frequency_filter)= {0} [s]'.format(elapsedTime))

    cv2.namedWindow(filename, cv2.WINDOW_AUTOSIZE)
    cv2.imshow(filename, im)
    cv2.imshow(filename, ipcv.histogram_enhancement(im))

    filterName = 'Filtered (' + filename + ')'
Beispiel #7
0
    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_lowpass(im,
    #                                    16,
    #                                    filterShape=ipcv.IPCV_IDEAL)
    frequencyFilter = ipcv.filter_lowpass(im,
                                          16,
                                          order=4,
                                          filterShape=ipcv.IPCV_BUTTERWORTH)
    # frequencyFilter = ipcv.filter_lowpass(im,
    #                                    16,
    #                                    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')
Beispiel #8
0
def filter_highpass(im, cutoffFrequency, order=1, filterShape=ipcv.IPCV_IDEAL):

   lowPass = ipcv.filter_lowpass(im,cutoffFrequency,order,filterShape)
   highPass = 1 - lowPass
   return highPass
Beispiel #9
0
if __name__ == '__main__':

    import cv2
    import ipcv
    import numpy
    import os.path
    import time

    home = os.path.expanduser('~')
    filename = home + os.path.sep + 'src/python/examples/data/lenna.tif'
    filename = home + os.path.sep + 'src/python/examples/data/giza.jpg'

    im = cv2.imread(filename, cv2.IMREAD_UNCHANGED)

    frequencyFilter = ipcv.filter_lowpass(im, 16, filterShape=ipcv.IPCV_IDEAL)

    startTime = time.clock()
    offset = 0
    filteredImage = ipcv.frequency_filter(im, frequencyFilter, delta=offset)
    filteredImage = numpy.abs(filteredImage)
    filteredImage = filteredImage.astype(dtype=numpy.uint8)
    elapsedTime = time.clock() - startTime
    print('Elapsed time (frequency_filter)= {0} [s]'.format(elapsedTime))

    cv2.namedWindow(filename, cv2.WINDOW_AUTOSIZE)
    cv2.imshow(filename, im)
    # cv2.imshow(filename, ipcv.histogram_enhancement(im))

    filterName = 'Filtered (' + filename + ')'
    cv2.namedWindow(filterName, cv2.WINDOW_AUTOSIZE)
Beispiel #10
0
   return filteredImage.astype(numpy.complex128)

if __name__ == '__main__':

   import cv2
   import ipcv
   import numpy
   import time

   #filename = '/cis/faculty/cnspci/public_html/courses/common/images/lenna_color.tif'
   #filename = 'lena_periodic.jpg'
   filename = '/cis/faculty/cnspci/public_html/courses/common/images/giza.jpg'
   im = cv2.imread(filename)

   frequencyFilter = ipcv.filter_lowpass(im, 
                                         32,2, 
                                         filterShape=ipcv.IPCV_GAUSSIAN)


   #notchCenter = [(32,0)]
   #notchRadius = [3]
   #frequencyFilter = ipcv.filter_notchreject(im,
   #                                          notchCenter,
   #                                          notchRadius,
   #                                          order=2,
   #                                          filterShape=ipcv.IPCV_GAUSSIAN)
   
   startTime = time.clock()
   offset = 0
   filteredImage = ipcv.frequency_filter(im, frequencyFilter, delta=offset)
   filteredImage = numpy.abs(filteredImage)