c++ - Implementing FFT low-pass filter in C with FFTW -
i trying create simple c++ program given argument in range [0-100] applies low-pass filter grayscale image should "compress" proprotionally value of given argument. using fftw library.
i have doubts how define frequency threshold, cut
. there more effective way define such value?
//fftw_complex *fft //double[] magnitude // . . . int percent = 100; if (percent < 0 || percent > 100) { cerr << "compression rate must value between 0 , 100." << endl; return -1; } double cut =(double)(w*h) * ((double)percent / (double)100); (i = 0; < (w * h); i++) { magnitude[i] = sqrt(pow(fft[i][0], 2.0) + pow(fft[i][1], 2.0)); if (magnitude[i] < cut) { fft[i][0] = 0.0; fft[i][1] = 0.0; } }
update1:
i've changed code this, again i'm not sure proper way filter frequencies. image surely compressed, non-square images messed , setting compression 100% isn't real maximum compression available (i can go ~140%). here can find image of see now.
int cx = w/2; int cy = h/2; cout<<"test "<<((double)percent/(double)100)*h<<endl; for(i = 0; i<(w*h);i++){ int row = i/s; int col = i%s; int distance = sqrt((col-cx)*(col-cx)+(row-cy)*(row-cy)); if(distance<((double)percent/(double)100)*min(cx,cy)){ fft[i][0] = 0.0; fft[i][1] = 0.0; } }
this not low-pass filter @ all. low-pass filter passes low frequencies, i.e. removes fine details (blurring). need 2d fft that.
this code removes random bits, essentially.
[edit] new code looks lot more low-pass filter. 141% setting expected: diagonal of square sqrt(2)=1.41 times side. converting index row/column pair should use image width, not random unexplained s
.
i don't know 0 frequency located. should easy spot (largest value) might in (0,0) instead of (w/2,h/2)
Thank you for sharing this detailed information with us. Continue to post. Just a few months ago, I needed a low pass filter. While looking online, I came upon the Anatech Electronics website. Then I decided to place my first order with them and I received all of my required low pass filters on time, for a lower price than others. You can also contact them if you need low pass filters.
ReplyDelete