48 lines
1.5 KiB
C++
48 lines
1.5 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <bitset>
|
|
|
|
#include "ImageSpotFinder.h"
|
|
#include "StrongPixelSet.h"
|
|
|
|
ImageSpotFinder::ImageSpotFinder(int32_t width, int32_t height)
|
|
: width(width), height(height), input_buffer(width * height), output_buffer(width * height / 32 + 1) {}
|
|
|
|
size_t ImageSpotFinder::OutputSize() const {
|
|
return (width * height) / 32 + ((width * height % 32 != 0) ? 1 : 0);
|
|
}
|
|
|
|
size_t ImageSpotFinder::OutputByteSize() const {
|
|
return OutputSize() * sizeof(uint32_t);
|
|
}
|
|
|
|
std::vector<int32_t> &ImageSpotFinder::GetInputBuffer() {
|
|
return input_buffer;
|
|
}
|
|
|
|
std::vector<DiffractionSpot> ImageSpotFinder::ExtractSpots(const SpotFindingSettings &settings, const std::vector<bool> &res_mask) {
|
|
StrongPixelSet pixel_set;
|
|
|
|
for (int i = 0; i < OutputSize(); i++) {
|
|
if (output_buffer[i]) {
|
|
std::bitset<32> bset = output_buffer[i];
|
|
for (int bit = 0; bit < 32; bit++) {
|
|
if (bset.test(bit)) {
|
|
size_t npixel = i * 32 + bit;
|
|
size_t col = npixel % width;
|
|
size_t line = npixel / width;
|
|
if (line < height && res_mask[npixel] == 0)
|
|
pixel_set.AddStrongPixel(col, line, input_buffer[npixel]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
std::vector<DiffractionSpot> vec;
|
|
pixel_set.FindSpotsImage(settings, vec);
|
|
return vec;
|
|
}
|
|
|
|
|