#include #include #include #include #include #include "fft.h" #include "image.h" 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) / 128.0, 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; image->red[idx] = filter (image->red[idx], dist); image->green[idx] = filter (image->green[idx], dist); image->blue[idx] = filter (image->blue[idx], dist); } } } int main (int argc, char **argv) { char *input; GdkPixbuf *pb; complex_image_t *image; g_type_init (); if (argc < 2) { printf ("Usage: %s \n\n", argv[0]); return 1; } input = argv[1]; if (!(pb = gdk_pixbuf_new_from_file (input, NULL))) { printf ("Could not open %s\n", input); return -1; } image = complex_image_from_pixbuf (pb); g_print ("width, height %d %d\n", image->width, image->height); complex_image_fft (image); complex_image_show ("test", image, CONVERT_MAG); low_pass (image, 2 * image->width); complex_image_show ("test", image, CONVERT_MAG); complex_image_ifft (image); complex_image_show ("test", image, CONVERT_RE); return 0; }