ImageSpotFinder: Getting ready for abstract class for both CPU and GPU spot finders
This commit is contained in:
@@ -5,15 +5,19 @@
|
||||
#include "StrongPixelSet.h"
|
||||
|
||||
ImageSpotFinderCPU::ImageSpotFinderCPU(size_t in_width, size_t in_height)
|
||||
: width(in_width), height(in_height) {}
|
||||
: width(in_width), height(in_height), in_buffer(in_width * in_height) {
|
||||
}
|
||||
|
||||
void ImageSpotFinderCPU::nbx(int input) {
|
||||
NBX = input;
|
||||
}
|
||||
|
||||
std::vector<DiffractionSpot> ImageSpotFinderCPU::Run(const int32_t *input,
|
||||
const SpotFindingSettings &settings,
|
||||
const std::vector<bool> &res_mask) {
|
||||
int32_t *ImageSpotFinderCPU::GetHostBuffer() {
|
||||
return in_buffer.data();
|
||||
}
|
||||
|
||||
std::vector<DiffractionSpot> ImageSpotFinderCPU::Run(const SpotFindingSettings &settings,
|
||||
const std::vector<bool> &res_mask) {
|
||||
std::vector<DiffractionSpot> output;
|
||||
StrongPixelSet strong_pixel_set;
|
||||
|
||||
@@ -21,11 +25,11 @@ std::vector<DiffractionSpot> ImageSpotFinderCPU::Run(const int32_t *input,
|
||||
if (settings.photon_count_threshold > 0) {
|
||||
for (int line = 0; line < height; line++) {
|
||||
for (int col = 0; col < width; col++) {
|
||||
int32_t pxl_val = input[line * width + col];
|
||||
int32_t pxl_val = in_buffer[line * width + col];
|
||||
if (pxl_val == INT32_MAX ||
|
||||
(pxl_val > settings.photon_count_threshold
|
||||
&& pxl_val != INT32_MIN
|
||||
&& !res_mask[line * width + col]))
|
||||
&& pxl_val != INT32_MIN
|
||||
&& !res_mask[line * width + col]))
|
||||
strong_pixel_set.AddStrongPixel(col, line, pxl_val);
|
||||
}
|
||||
}
|
||||
@@ -47,8 +51,8 @@ std::vector<DiffractionSpot> ImageSpotFinderCPU::Run(const int32_t *input,
|
||||
for (int col = 0; col < width; col++) {
|
||||
auto pxl = line * width + col;
|
||||
|
||||
if (input[pxl] != INT32_MAX && input[pxl] != INT32_MIN) {
|
||||
int64_t tmp = input[pxl];
|
||||
if (in_buffer[pxl] != INT32_MAX && in_buffer[pxl] != INT32_MIN) {
|
||||
int64_t tmp = in_buffer[pxl];
|
||||
sum_vert[col] += tmp;
|
||||
sum2_vert[col] += tmp * tmp;
|
||||
valid_vert[col] += 1;
|
||||
@@ -62,8 +66,8 @@ std::vector<DiffractionSpot> ImageSpotFinderCPU::Run(const int32_t *input,
|
||||
if (line < height - NBX) {
|
||||
auto pxl = (line + NBX) * width + col;
|
||||
|
||||
if (input[pxl] != INT32_MAX && input[pxl] != INT32_MIN) {
|
||||
int64_t tmp = input[pxl];
|
||||
if (in_buffer[pxl] != INT32_MAX && in_buffer[pxl] != INT32_MIN) {
|
||||
int64_t tmp = in_buffer[pxl];
|
||||
sum_vert[col] += tmp;
|
||||
sum2_vert[col] += tmp * tmp;
|
||||
valid_vert[col] += 1;
|
||||
@@ -72,8 +76,8 @@ std::vector<DiffractionSpot> ImageSpotFinderCPU::Run(const int32_t *input,
|
||||
|
||||
if (line >= NBX + 1) {
|
||||
auto pxl = (line - (NBX + 1)) * width + col;
|
||||
if (input[pxl] != INT32_MAX && input[pxl] != INT32_MIN) {
|
||||
int64_t tmp = input[pxl];
|
||||
if (in_buffer[pxl] != INT32_MAX && in_buffer[pxl] != INT32_MIN) {
|
||||
int64_t tmp = in_buffer[pxl];
|
||||
sum_vert[col] -= tmp;
|
||||
sum2_vert[col] -= tmp * tmp;
|
||||
valid_vert[col] -= 1;
|
||||
@@ -104,7 +108,7 @@ std::vector<DiffractionSpot> ImageSpotFinderCPU::Run(const int32_t *input,
|
||||
valid -= valid_vert[col - NBX - 1];
|
||||
}
|
||||
|
||||
int32_t pxl_val = input[line * width + col];
|
||||
int32_t pxl_val = in_buffer[line * width + col];
|
||||
int64_t var = valid * sum2 - (sum * sum);
|
||||
int64_t in_minus_mean = pxl_val * valid - sum;
|
||||
|
||||
@@ -113,11 +117,8 @@ std::vector<DiffractionSpot> ImageSpotFinderCPU::Run(const int32_t *input,
|
||||
(pxl_val > settings.photon_count_threshold) && // pixel is above count threshold
|
||||
(in_minus_mean > 0) && // pixel value is larger than mean
|
||||
(in_minus_mean * in_minus_mean > std::ceil(var * strong2)) && // pixel is above SNR threshold
|
||||
(res_mask[line * width + col] == 0))) {
|
||||
// pixel is within a valid resolution range
|
||||
std::cout << line << " " << col << std::endl;
|
||||
(res_mask[line * width + col] == 0))) // pixel is within a valid resolution range
|
||||
strong_pixel_set.AddStrongPixel(col, line, pxl_val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user