/*********************************************************** * freqFilter.cpp - perform frequency domain filtering * * - ideal: the ideal highpass/lowpass filter * - butterworth: the butterworth highpass/lowpass filter * - gaussianFreq: the Gaussian highpass/lowpass filter * - inverseFilter: the inverse filter * - wiener: the Wiener filter * * Author: Hairong Qi (C) hqi@utk.edu * ***********************************************************/ #include "Image.h" #include "Dip.h" #include #include using namespace std; /** * Ideal highpass/lowpass filter. * @param inimg The input image. * @param flag The flag that controls either lowpass or highpass operation. * @see HIGH. * @see LOW. * @param radius The radius of the filter. * @return The filtered image. */ Image ideal(Image &inimg, int flag, float radius) { Image outimg, filter, mag, phase; int nr, nc; double dist; nr = inimg.getRow(); nc = inimg.getCol(); // generate the ideal filter filter.createImage(nr, nc); for (int i=0; i radius ) ? 1 : 0; else // lowpass ideal filter(i,j) = ( dist <= radius ) ? 1 : 0; } // FFT of the input image mag.createImage(nr, nc); phase.createImage(nr, nc); fft(inimg, mag, phase); // apply the ideal filter mag = mag * filter; // inverse FFT outimg.createImage(nr, nc); ifft(outimg, mag, phase); return outimg; } /** * Butterworth highpass/lowpass filter. * @param inimg The input image. * @param flag The flag that controls either lowpass or highpass operation. * @see HIGH. * @see LOW. * @param radius The radius of the filter. * @param n The exponent that controls the sharpness of the filter. * @return The filtered image. */ Image butterworth(Image &inimg, int flag, float radius, int n) { Image outimg, filter, mag, phase; int nr, nc; double dist; nr = inimg.getRow(); nc = inimg.getCol(); // generate the butterworth filter filter.createImage(nr, nc); for (int i=0; i