/*ffttest3 is ffttest2, aangepast voor het dynamisch bereik van de fft, en met het op de juiste plaats zetten van de vier kwadranten*/ #include #include #include #include #include #include int * kanaal(int w,int h, ImlibImage *im, int chan) { int i,j; int index; int *out=malloc(sizeof(int)*w*h); for(i=0; irgb_data[index+chan]; } } return out; } fftw_complex * fourier(int *kanaal, int w, int h) { fftw_complex *in, *out; fftwnd_plan p; int i,j; in = (fftw_complex *) malloc(w*h*sizeof(fftw_complex)); out= (fftw_complex *) malloc(w*h*sizeof(fftw_complex)); for (i=0; i < w; i ++) { for (j=0; j < h; j++) { in[i+j*w].re = kanaal[i+j*w]; in[i+j*w].im = 0; } } p = fftw2d_create_plan(w, h , FFTW_FORWARD, FFTW_ESTIMATE); fftwnd_one(p, &in[0], &out[0]); return out; } int main(int argc, char **argv) { int teller; int chan; int *red; int *green; int *blue; fftw_complex *fourred; fftw_complex *fourgreen; fftw_complex *fourblue; int w,h,i,j; double argmn; ImlibData *id; ImlibData *id2; ImlibImage *im; ImlibImage *im2; Display *disp; disp = XOpenDisplay(NULL); id = Imlib_init(disp); id2 = Imlib_init(disp); /* Load the image specified as the first argument */ im =Imlib_load_image(id , argv[1]); im2=Imlib_load_image(id2, argv[1]); /* Suck the image's original width and height out of the Image structure */ w=im->rgb_width; h=im->rgb_height; red = kanaal(w, h, im, 0); green = kanaal(w, h, im, 1); blue = kanaal(w, h, im, 2); fourred = fourier(red, w, h); fourgreen = fourier(green, w, h); fourblue = fourier(blue, w, h); i=0; while (i < w) { j = 0; while (j < h) { int k,l; int index1, index2 ; int temp; index1 = (i + w*j)*3; if (i < w/2) {k=i + (w/2);} if (j < h/2) {l=j + (h/2);} if (i >=w/2) {k=i - (w/2);} if (j >=h/2) {l=j - (h/2);} index2 = (k+w*l)*3; temp =log(((fourred[index1/3].re * fourred[index1/3].re + fourred[index1/3].im * fourred[index1/3].im)))*5; if (temp < 0) {temp=0;} if (temp > 255) {temp = 255;} im2->rgb_data[index2] = temp; temp = log(((fourgreen[index1/3].re * fourgreen[index1/3].re + fourgreen[index1/3].im * fourgreen[index1/3].im)))*5; if (temp < 0) {temp=0;} if (temp > 255) {temp = 255;} im2->rgb_data[index2+1] = temp; temp = log(((fourblue[index1/3].re * fourblue[index1/3].re + fourblue[index1/3].im * fourblue[index1/3].im)))*5; if (temp < 0) {temp=0;} if (temp > 255) {temp = 255;} im2->rgb_data[index2+2] = temp; j ++; } i ++; } Imlib_save_image_to_ppm(id2,im2, argv[2]); return 1; }