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);
70 printf(
"\nMax real:%f Min real:%f\n", i1.maxCoeff(), i1.minCoeff());
79 for (
y = 0;
y < ly;
y++)
80 for (
x = 0;
x < lx;
x++)
82 float r1 = I1_R(
y,
x);
83 float r2 = I2_R(
y,
x);
84 float i1 = I1_I(
y,
x);
85 float i2 = I2_I(
y,
x);
87 I2_R(
y,
x) = r1 * r2 - i1 * i2;
88 I2_I(
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.maxCoeff(), res_R.minCoeff());
100 printf(
"Mean time: %.06fms\n", 1000.0f * meanTime / N);
106 winR.showImage(imgR);
124 catch (
const std::exception& e)
131 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 setFromMatrix(const MAT &m, bool matrix_is_normalized=true)
Set the image from a matrix, interpreted as grayscale intensity values, in the range [0...
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 class is a "CSerializable" wrapper for "CMatrixFloat".
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Classes for creating GUI windows for 2D and 3D visualization.
void Tic() noexcept
Starts the stopwatch.
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.
void loadFromTextFile(std::istream &f)
Loads a vector/matrix from a text file, compatible with MATLAB text format.