36 const std::pair<size_t, size_t> &borders,
40 assert(micrograph.
x() >= patch.
x());
41 assert(micrograph.
y() >= patch.
y());
42 assert((2 * borders.first + patch.
x()) <= micrograph.
x());
43 assert((2 * borders.second + patch.
y()) <= micrograph.
y());
44 assert(overlap >= 0.
f);
45 assert(overlap < 1.
f);
47 size_t stepX =
std::max((1 - overlap) * patch.
x(), 1.f);
48 size_t stepY =
std::max((1 - overlap) * patch.
y(), 1.f);
50 size_t maxX = micrograph.
x() - borders.first - patch.
x();
51 size_t maxY = micrograph.
y() - borders.second - patch.
y();
53 auto result = std::vector<Rectangle<Point2D<size_t>>>();
55 size_t y = borders.second;
56 while (y < (maxY + stepY)) {
58 size_t ye = ys + patch.
y() - 1;
59 size_t x = borders.first;
60 while (x < (maxX + stepX)) {
62 size_t xe = xs + patch.
x() - 1;
65 result.emplace_back(tl, br);
79 auto patches = getPatchesLocation({0, 0},
87 auto *data =
reinterpret_cast<T*
>(transformer::allocateAligned(settings.sBytesSingle()));
94 auto patchFS = (std::complex<T>*)transformer::allocateAligned(settings.fBytesBatch());
95 auto magnitudes =
new T[settings.fElemsBatch()]();
97 auto hw =
CPU(fftThreads);
98 auto plan = transformer::createPlan(hw, settings,
true);
100 for (
auto &p : patches) {
103 p.tl.y, p.tl.x, p.br.y, p.br.x);
105 patchData.statisticsAdjust((T)0, (T)1);
106 patchData.resetOrigin();
108 patchData *= smoother;
110 transformer::fft(plan, patchData.data, patchFS);
112 for (
size_t n = 0;
n < settings.fElemsBatch(); ++
n) {
114 auto mag =
sqrt((v.real() * v.real()) + (v.imag() * v.imag()));
115 magnitudes[
n] += mag;
121 half2whole(magnitudes, psd.
data, settings, [&](
bool mirror, T val){return val;});
128 if (pixval > 0 && pixval < min_val)
131 min_val = 10 *
log10(min_val);
144 transformer::release(patchFS);
145 transformer::release(plan);
146 transformer::release(data);
void min(Image< double > &op1, const Image< double > &op2)
#define A2D_ELEM(v, i, j)
void resizeNoCopy(const MultidimArray< T1 > &v)
void sqrt(Image< double > &op)
static void constructPieceSmoother(const MultidimArray< T > &piece, MultidimArray< T > &pieceSmoother)
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
CUDA_HD constexpr size_t x() const
void reject_outliers(T &v, double percentil_out=0.25)
quaternion_type< T > normalize(quaternion_type< T > q)
void max(Image< double > &op1, const Image< double > &op2)
CUDA_HD constexpr size_t y() const
void log10(Image< double > &op)
void window2D(const MultidimArray< T > &Ibig, MultidimArray< T > &Ismall, size_t y0, size_t x0, size_t yF, size_t xF)
static void estimatePSD(const MultidimArray< T > µgraph, float overlap, const Dimensions &tileDim, MultidimArray< T > &psd, unsigned fftThreads, bool normalize)
static std::vector< Rectangle< Point2D< size_t > > > getPatchesLocation(const std::pair< size_t, size_t > &borders, const Dimensions µgraph, const Dimensions &patch, float overlap)