imgcv.filters.freq_domain
Functions
|
Calculates 2D Fast Fourier Transform of an image. It is a recursive function based on the Cooley-Tukey algorithm. Computes the 2D DFT of an image or array of images in O(n^2 log n) time. |
|
Calculates 2D Inverse Fast Fourier Transform of a specturm. It is a recursive function based on the Cooley-Tukey algorithm. Computes the 2D IDFT of a specturm or array of specturms in O(n^2 log n) time. |
|
Shifts the zero frequency component to the center of the spectrum. |
|
Apply low pass filter in the frequency domain to an image. |
|
Apply high pass filter in the frequency domain to an image. |
Module Contents
- imgcv.filters.freq_domain.fft2(image)
Calculates 2D Fast Fourier Transform of an image. It is a recursive function based on the Cooley-Tukey algorithm. Computes the 2D DFT of an image or array of images in O(n^2 log n) time.
NOTE: Currently works only for square images and gray scale with size as power of 2.
- Parameters:
image (np.ndarray) – Input image to calculate 2D FFT.
- Returns:
2D FFT of the input image. The output is a complex array.
- Return type:
np.ndarray
- imgcv.filters.freq_domain.ifft2(specturm)
Calculates 2D Inverse Fast Fourier Transform of a specturm. It is a recursive function based on the Cooley-Tukey algorithm. Computes the 2D IDFT of a specturm or array of specturms in O(n^2 log n) time.
- Parameters:
specturm (np.ndarray) – Input specturm to calculate 2D IFFT. The input is a complex array.
- Returns:
2D IFFT of the input specturm. The output is a complex array.
- Return type:
np.ndarray
- imgcv.filters.freq_domain.fftshift(spectrum)
Shifts the zero frequency component to the center of the spectrum.
- Parameters:
spectrum (np.ndarray) – Input spectrum to shift.
- Raises:
ValueError – If spectrum is not a numpy array.
ValueError – If spectrum is not 2D.
ValueError – If spectrum is not square and size is not power of 2.
- Returns:
Shifted spectrum.
- Return type:
np.ndarray
- imgcv.filters.freq_domain.low_pass_filter(img, cutoff, order=None, type='butterworth', return_img_fft=False)
Apply low pass filter in the frequency domain to an image. NOTE: Currently works only for square images and gray scale with size as power of 2.
- Parameters:
img (np.ndarray) – Input image to apply low pass filter.
cutoff (int) – Cutoff frequency of the filter.
order (int, optional) – Order of the Butterworth filter. Defaults to None. If None, order is set to 1.
type (str, optional) – Type of the filter. Choose one of ‘ideal’, ‘butterworth’, ‘gaussian’. Defaults to “butterworth”.
return_img_fft (bool, optional) – If True, return the filtered image in the frequency domain along with the original image in the frequency domain. Defaults to False.
- Raises:
ValueError – If input image is not a numpy array.
ValueError – If input image is not 2D.
ValueError – If cutoff frequency is not an integer.
ValueError – If order is not an integer.
ValueError – If filter type is invalid.
- Returns:
Filtered image in the spatial domain. (np.ndarray, np.ndarray): Filtered image in the frequency domain and the original image in the frequency domain (if return_img_fft is True)
- Return type:
np.ndarray
- imgcv.filters.freq_domain.high_pass_filter(img, cutoff, order=None, type='butterworth', return_img_fft=False)
Apply high pass filter in the frequency domain to an image. NOTE: Currently works only for square images and gray scale with size as power of 2.
- Parameters:
img (np.ndarray) – Input image to apply high pass filter.
cutoff (int) – Cutoff frequency of the filter.
order (int, optional) – Order of the Butterworth filter. Defaults to None. If None, order is set to 1.
type (str, optional) – Type of the filter. Choose one of ‘ideal’, ‘butterworth’, ‘gaussian’. Defaults to “butterworth”.
return_img_fft (bool, optional) – If True, return the filtered image in the frequency domain along with the original image in the frequency domain. Defaults to False.
- Raises:
ValueError – If input image is not a numpy array.
ValueError – If input image is not 2D.
ValueError – If cutoff frequency is not an integer.
ValueError – If order is not an integer.
ValueError – If filter type is invalid.
- Returns:
Filtered image in the spatial domain. (np.ndarray, np.ndarray): Filtered image in the frequency domain and the original image in the frequency domain (if return_img_fft is True)
- Return type:
np.ndarray