24 #include <mrpt/examples_config.h> 26 MRPT_EXAMPLES_BASE_DIRECTORY +
27 string(
"img_correlation_example/"));
37 printf(
"Loading matrix from file...");
38 A.loadFromTextFile(
"dft2_test.txt");
42 "Computing 2D FFT of %ux%u...", (
unsigned int)A.rows(),
43 (
unsigned int)A.cols());
46 printf(
" Done,%.06fms\n", tictac.
Tac() * 1000.0f);
48 RES_R.saveToTextFile(
"_out_dft2_real.txt");
49 RES_I.saveToTextFile(
"_out_dft2_imag.txt");
52 "Computing 2D IFFT of %ux%u...", (
unsigned int)A.rows(),
53 (
unsigned int)A.cols());
56 printf(
" Done,%.06fms\n", tictac.
Tac() * 1000.0f);
64 D.find_index_max_value(u,
v, maxError);
66 printf(
"Maximum error between 'A' and 'IFFT(FFT(A))'=%e\n", maxError);
74 CMatrix DATA_R, DATA_I, RES_R, RES_I, B_R, B_I, D_R, D_I;
77 printf(
"Loading matrix from file...");
78 DATA_R.loadFromTextFile(
"complex_dft2_test_real.txt");
79 DATA_I.loadFromTextFile(
"complex_dft2_test_imag.txt");
83 "Computing 2D complex FFT of %ux%u...", (
unsigned int)DATA_R.rows(),
84 (
unsigned int)DATA_R.cols());
87 printf(
" Done,%.06fms\n", tictac.
Tac() * 1000.0f);
89 RES_R.saveToTextFile(
"_out_complex_dft2_real.txt");
90 RES_I.saveToTextFile(
"_out_complex_dft2_imag.txt");
93 "Computing 2D complex IFFT of %ux%u...", (
unsigned int)DATA_R.rows(),
94 (
unsigned int)DATA_R.cols());
97 printf(
" Done,%.06fms\n", tictac.
Tac() * 1000.0f);
104 float maxError_R, maxError_I;
106 D_R.find_index_max_value(u,
v, maxError_R);
107 D_I.find_index_max_value(u,
v, maxError_I);
109 printf(
"Maximum error between 'A' and 'IFFT(FFT(A))'=%e\n", maxError_R);
110 printf(
"Maximum error between 'A' and 'IFFT(FFT(A))'=%e\n", maxError_I);
123 myDataDir +
string(
"fft2_test_image_patch.jpg"), 0);
125 myDataDir +
string(
"fft2_test_image.jpg"), 0);
127 printf(
"Computing images correlation...");
130 printf(
" Done,%.06fms\n", tictac.
Tac() * 1000.0f);
132 imgCorr.saveToTextFile(
"_out_dft2_image_test.txt");
171 if (!
img.loadFromFile(
"../img_basic_example/frame_color.bmp"))
173 cerr <<
"Error loading ../img_basic_example/frame_color.bmp" 177 printf(
"bmp file loaded in %.03fms\n", 1000.0f * tictac.
Tac());
184 img.loadFromFile(
"frame_gray.bmp");
185 printf(
"bmp file loaded in %.03fms\n", 1000.0f * tictac.
Tac());
194 img.loadFromFile(
"frame.jpg");
195 printf(
"jpeg file loaded in %.03fms\n", 1000.0f * tictac.
Tac());
200 CImage imgSmall2(imgSmall.scaleHalf());
201 CImage imgGray(imgSmall2.grayscale());
207 imgSmall.line(550, 75, 650, 25,
TColor(0, 0, 255));
208 imgSmall.line(-10, -20, 20, 30,
TColor(0, 0, 255));
213 COV(0, 1) = COV(1, 0) = -30;
214 imgSmall.ellipseGaussian(&COV, 600.0f, 50.0f, 2,
TColor(255, 255, 0), 4);
215 imgGray.ellipseGaussian(&COV, 100.0f, 100.0f, 2,
TColor(0, 0, 255), 4);
217 imgSmall.drawImage(400, 500, imgGray);
221 win1.showImage(imgSmall);
223 win2.showImage(imgSmall2);
225 win3.showImage(imgGray);
226 win3.setPos(810, 400);
232 printf(
"jpeg file loaded in %.03fms\n", 1000.0f * tictac.
Tac());
288 catch (std::exception& e)
290 std::cout <<
"MRPT exception caught: " << e.what() << std::endl;
295 printf(
"Untyped exception!!");
double Tac() noexcept
Stops the stopwatch.
int getch() noexcept
An OS-independent version of getch, which waits until a key is pushed.
void dft2_real(const CMatrixFloat &in_data, CMatrixFloat &out_real, CMatrixFloat &out_imag)
Compute the 2D Discrete Fourier Transform (DFT) of a real matrix, returning the real and imaginary pa...
A high-performance stopwatch, with typical resolution of nanoseconds.
bool loadFromFile(const std::string &fileName, int isColor=-1)
Load image from a file, whose format is determined from the extension (internally uses OpenCV)...
This base provides a set of functions for maths stuff.
This class creates a window as a graphical user interface (GUI) for displaying images to the user...
void rectangle(int x0, int y0, int x1, int y1, const mrpt::img::TColor color, unsigned int width=1)
Draws a rectangle (an empty rectangle, without filling)
void cross_correlation_FFT(const CImage &in_img, math::CMatrixFloat &out_corr, int u_search_ini=-1, int v_search_ini=-1, int u_search_size=-1, int v_search_size=-1, float biasThisImg=0, float biasInImg=0) const
Computes the correlation matrix between this image and another one.
void idft2_complex(const CMatrixFloat &in_real, const CMatrixFloat &in_imag, CMatrixFloat &out_real, CMatrixFloat &out_imag)
Compute the 2D inverse Discrete Fourier Transform (DFT).
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void idft2_real(const CMatrixFloat &in_real, const CMatrixFloat &in_imag, CMatrixFloat &out_data)
Compute the 2D inverse Discrete Fourier Transform (DFT)
void TestFFT_2D_complex()
Classes for creating GUI windows for 2D and 3D visualization.
bool saveToFile(const std::string &fileName, int jpeg_quality=95) const
Save the image to a file, whose format is determined from the extension (internally uses OpenCV)...
void Tic() noexcept
Starts the stopwatch.
This class is a "CSerializable" wrapper for "CMatrixFloat".
void dft2_complex(const CMatrixFloat &in_real, const CMatrixFloat &in_imag, CMatrixFloat &out_real, CMatrixFloat &out_imag)
Compute the 2D Discrete Fourier Transform (DFT) of a complex matrix, returning the real and imaginary...
void TestImageConversion()
A class for storing images as grayscale or RGB bitmaps.