Views
3 years ago

Lode's Computer Graphics Tutorial Fourier Transform

Lode's Computer Graphics Tutorial Fourier Transform

different filters and

different filters and see their effect. The full code can be downloaded here: fourier2d.cpp.This code doesn't contain much new, it's much more interesting to run it and study the results of thefilters.Once again, first come all the declarations of functions and variables. f2 and F2 will become the buffersfor the filtered versions of the original image and spectrum.//yeah, we're working with fixed sizes again...const int N = 128; //the width of the imageconst int M = 128; //the height of the imagedouble fRe[N][M][3], fIm[N][M][3], fAmp[N][M][3]; //the signal's real part, imaginary part, and amplitudedouble FRe[N][M][3], FIm[N][M][3], FAmp[N][M][3]; //the FT's real part, imaginary part and amplitudedouble fRe2[N][M][3], fIm2[N][M][3], fAmp2[N][M][3]; //will become the signal again after IDFT of the spectrumdouble FRe2[N][M][3], FIm2[N][M][3], FAmp2[N][M][3]; //filtered spectrumdouble pi = 3.1415926535897932384626433832795;void draw(int xpos, int yPos, int n, int m, double *g, bool shift, bool neg128);void FFT2D(int n, int m, bool inverse, double *gRe, double *gIm, double *GRe, double *GIm);void calculateAmp(int n, int m, double *ga, double *gRe, double *gIm);The main function loads a PNG image first, and will then start the first loop, the loop that lets you tryout different modified versions of the PNG image and some other generated signals:int main(int /*argc*/, char */*argv*/[]){screen(3 * N,4 * M + 8, 0,"2D FFT and Filters");std::vector img;unsigned long dummyw, dummyh;if(loadImage(img, dummyw, dummyh, "pics/test.png")){print("image pics/test.png not found");redraw();sleep();cls();}//set signal to the imagefor(int x = 0; x < N; x++)for(int y = 0; y < M; y++){fRe[x][y][0] = img[N * y + x].r;fRe[x][y][1] = img[N * y + x].g;fRe[x][y][2] = img[N * y + x].b;}int ytrans=8; //translate everything a bit down to put the text on top//set new FT buffersfor(int x = 0; x < N; x++)for(int y = 0; y < M; y++)for(int c = 0; c < 3; c++){FRe2[x][y][c] = FRe[x][y][c];FIm2[x][y][c] = FIm[x][y][c];}bool changed = 1, endloop = 0;while(!endloop){if(done()) end();readKeys();Here's a small part of the input part of the first loop, it looks pretty messy here, only a few keys are

shown here, the code for all keys is included in the downloadable file.if(keyPressed(SDLK_a) || changed){for(int x = 0; x < N; x++)for(int y = 0; y < M; y++)for(int c = 0; c < 3; c++){fRe2[x][y][c] = fRe[x][y][c];} changed = 1;} //no effectif(keyPressed(SDLK_b)){for(int x = 0; x < N; x++)for(int y = 0; y < M; y++)for(int c = 0; c < 3; c++){fRe2[x][y][c] = 255 - fRe[x][y][c];}changed = 1;} //negativeif(keyPressed(SDLK_c)){for(int x = 0; x < N; x++)for(int y = 0; y < M; y++)for(int c = 0; c < 3; c++){fRe2[x][y][c] = fRe[x][y][c]/2;}changed = 1;} //half amplitude//ETCETERA... *snip*if(keyPressed(SDLK_SPACE)) endloop = 1;If a key was pressed, the new version of the image and it's spectrum will be drawn. If the first loop wasdone (by pressing space), the second loop is initialized:if(changed){//Draw the image and it's FTcalculateAmp(N, M, fAmp2[0][0], fRe2[0][0], fIm2[0][0]);draw(0, ytrans, N, M, fRe2[0][0], 0, 0); draw(N, 0+ytrans, N, M, fIm2[0][0], 0, 0);draw(2 * N, 0+ytrans, N, M, fAmp2[0][0], 0, 0); //draw real, imag and amplitudeFFT2D(N, M, 0, fRe2[0][0], fIm2[0][0], FRe[0][0], FIm[0][0]);calculateAmp(N, M, FAmp[0][0], FRe[0][0], FIm[0][0]);draw(0,M + ytrans, N, M, FRe[0][0], 1, 1); draw(N, M + ytrans, N, M, FIm[0][0], 1, 1);draw(2 * N, M + ytrans, N, M, FAmp[0][0], 1, 0); //draw real, imag and amplitudeprint("Press a-z for effects and space to accept", 0, 0, RGB_White, 1, ColorRGB(128, 0, 0));redraw();}changed = 0;}changed = 1;while(!done()){readKeys();Here's a small part of the input code to apply filters: a Low Pass, High Pass and Band Pass filter aregiven. The rest of the keys is in the downloadable file.if(keyPressed(SDLK_f)){for(int x = 0; x < N; x++)for(int y = 0; y < M; y++)

Introduction to Fourier Transform Infrared ... - Nicolet CZ sro
CSC418: Computer Graphics Tutorial 1 - CDF
Chapter 36 Fast Fourier Transform and N - Phase ... - E-Courses
SLEVES and SLEFES - Computer Graphics Laboratory
THE WAVELET TUTORIAL PART II by ROBI POLIKAR
Real-Time Interaction Behavior - Computer Graphics and Visualization
Fourier Transform Graphical Analysis: an Approach for Digital Image ...
Tutorial : , & coherence with M 1 Fourier transform by Fast Fourier ...
Fast Clifford Fourier Transformation for - Computer Science and ...
Analysis/resynthesis with the short time Fourier transform
Fourier transforms & the convolution theorem - UGAstro
Fundamentals of the Discrete Fourier Transform
Exercises in MATLAB for convolution and Fourier transform These ...
Fast Fourier Transform and MATLAB Implementation
Lecture: Fourier Transform - biomachina.org
The Fast Fourier Transform - LOMONT.org
some notes on the Fourier transform - IGPP
Fourier Slice Photography - Computer Graphics Laboratory ...
Lecture SS4 – Fourier Transforms