#include #include #include #include #include #include "fft.h" #include "image.h" static void image_fft (complex_image_t *image) { fft_shift_2d (image->red, image->width); fft_shift_2d (image->green, image->width); fft_shift_2d (image->blue, image->width); } static void image_ifft (complex_image_t *image) { ifft_shift_2d (image->red, image->width); ifft_shift_2d (image->green, image->width); ifft_shift_2d (image->blue, image->width); } static complex_t filter (complex_t c, double dist) { double m = complex_mag (c); double arg = complex_arg (c); return complex_from_mag_arg (m * (1/(pow (sqrt (dist) / 16, 4) + 1)) , arg); } static void low_pass (complex_image_t *image, double d) { int w = image->width; int h = image->height; int i, j; double d2 = d * d; int c = h / 2; for (i = 0; i < h; ++i) { for (j = 0; j < w; ++j) { int idx = i * w + j; double dist = (c - i) * (c - i) + (c - j) * (c -j); double t; if (dist > 2) { image->red[idx] = filter (image->red[idx], dist); image->green[idx] = filter (image->green[idx], dist); image->blue[idx] = filter (image->blue[idx], dist); } else { image->red[idx].re = image->red[idx].im = 0; image->green[idx].re = image->green[idx].im = 0; image->blue[idx].re = image->blue[idx].im = 0; } } } } static void make_noise (complex_image_t *image) { int i, j; int h, w; h = image->height; w = image->width; for (i = 0; i < h; ++i) { for (j = 0; j < w; ++j) { int idx = i * w + j; double n = 0.5 * (drand48() + drand48()); image->red[idx].re = n; image->green[idx].re = n; image->blue[idx].re = n; } } } int main (int argc, char **argv) { char *input, *output; GdkPixbuf *pb; complex_image_t *image; complex_image_t *low_passed; g_type_init (); image = complex_image_new (32, 32); make_noise (image); complex_image_show ("test", image, CONVERT_RE); image_fft (image); low_passed = complex_image_copy (image); low_pass (low_passed, 2 * image->width); complex_image_show ("low passed", low_passed, CONVERT_MAG); complex_image_subtract (image, low_passed); complex_image_show ("ssubtracted", image, CONVERT_MAG); image_ifft (image); complex_image_show ("test", image, CONVERT_RE); return 0; }