24 #include <mrpt/examples_config.h> 25 string myDataDir(MRPT_EXAMPLES_BASE_DIRECTORY +
string(
"img_convolution_fft/"));
37 if (!
img.loadFromFile(
myDataDir +
string(
"test_image.jpg")))
38 throw std::runtime_error(
"Cannot load test image!");
41 "Computing %ux%u image convolution ...", (
unsigned)
img.getWidth(),
42 (unsigned)
img.getHeight());
51 for (
int nTimes = 0; nTimes < N; nTimes++)
56 size_t actual_lx =
img.getWidth();
57 size_t actual_ly =
img.getHeight();
63 img.getAsMatrix(i1,
false);
66 i2.loadFromTextFile(
myDataDir +
string(
"test_convolution_window.txt"));
70 printf(
"\nMax real:%f Min real:%f\n", i1.maximum(), i1.minimum());
79 for (
y = 0;
y < ly;
y++)
80 for (
x = 0;
x < lx;
x++)
82 float r1 = I1_R.get_unsafe(
y,
x);
83 float r2 = I2_R.get_unsafe(
y,
x);
84 float i1 = I1_I.get_unsafe(
y,
x);
85 float i2 = I2_I.get_unsafe(
y,
x);
87 I2_R.set_unsafe(
y,
x, r1 * r2 - i1 * i2);
88 I2_I.set_unsafe(
y,
x, r2 * i1 + r1 * i2);
95 meanTime += tictac.
Tac();
96 printf(
" Done,%.06fms\n", tictac.
Tac() * 1000.0f);
97 printf(
"Max real:%f Min real:%f\n", res_R.maximum(), res_R.minimum());
100 printf(
"Mean time: %.06fms\n", 1000.0f * meanTime / N);
104 res_R.adjustRange(0, 1);
107 winR.showImage(imgR);
125 catch (std::exception& e)
127 std::cout <<
"MRPT exception caught: " << e.what() << std::endl;
132 printf(
"Untyped exception!!");
double Tac() noexcept
Stops the stopwatch.
A high-performance stopwatch, with typical resolution of nanoseconds.
void TestImageConvolutionFFT()
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...
T round2up(T val)
Round up to the nearest power of two of a given number.
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.
Classes for creating GUI windows for 2D and 3D visualization.
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...
A class for storing images as grayscale or RGB bitmaps.