SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
FFTHelper.h
Go to the documentation of this file.
1
17
18#ifndef _SEFRAMEWORK_FFT_FFTHELPER_H
19#define _SEFRAMEWORK_FFT_FFTHELPER_H
20
22#include <cassert>
23#include <vector>
24
25namespace SourceXtractor {
26
43template <typename T, template <typename> class Img>
44static void copyImageToFFTWorkArea(Img<T>& origin, std::vector<T>& buffer) {
45 int width = origin.getWidth();
46 int height = origin.getHeight();
47 int pad = 2 * (width / 2 + 1) - width;
48 int stride = width + pad;
49 assert(buffer.size() == static_cast<size_t>(height * (width + pad)));
50 for (int y = 0; y < height; ++y) {
51 for (int x = 0; x < width; ++x) {
52 buffer[x + y * stride] = origin.getValue(x, y);
53 }
54 }
55}
56
86template <typename T, template <typename> class Img>
87static void copyFFTWorkAreaToImage(std::vector<T>& buffer, Img<T>& dest, int rpad = 0, int lpad = 0, int tpad = 0, int bpad = 0,
88 bool normalize = true) {
89 const int width = dest.getWidth();
90 const int height = dest.getHeight();
91 const int padded_width = width + rpad + lpad;
92 const int padded_height = height + tpad + bpad;
93 const int fftw_pad = 2 * (padded_width / 2 + 1) - padded_width;
94 const int stride = padded_width + fftw_pad;
95 const int total_size = normalize ? padded_width * padded_height : 1;
96 assert(buffer.size() == static_cast<size_t>(padded_height * (padded_width + fftw_pad)));
97 for (int y = 0; y < height; ++y) {
98 for (int x = 0; x < width; ++x) {
99 dest.setValue(x, y, buffer[x + lpad + (y + tpad) * stride] / total_size);
100 }
101 }
102}
103
104} // namespace SourceXtractor
105
106#endif // _SEFRAMEWORK_FFT_FFTHELPER_H
static void copyFFTWorkAreaToImage(std::vector< T > &buffer, Img< T > &dest, int rpad=0, int lpad=0, int tpad=0, int bpad=0, bool normalize=true)
Definition FFTHelper.h:87
static void copyImageToFFTWorkArea(Img< T > &origin, std::vector< T > &buffer)
Definition FFTHelper.h:44
T size(T... args)