diff --git a/image_analysis/MXAnalysisWithoutFPGA.cpp b/image_analysis/MXAnalysisWithoutFPGA.cpp index 2ee7a2a3..922ce31b 100644 --- a/image_analysis/MXAnalysisWithoutFPGA.cpp +++ b/image_analysis/MXAnalysisWithoutFPGA.cpp @@ -49,7 +49,7 @@ void MXAnalysisWithoutFPGA::Analyze(DataMessage &output, output.preprocessing_time_s = std::chrono::duration(preprocessing_end_time - preprocessing_start_time).count(); const auto azint_start_time = std::chrono::steady_clock::now(); - preprocessor->AzimIntegration(integration, profile); + spotFinder->AzimIntegration(integration, profile); const auto azint_end_time = std::chrono::steady_clock::now(); output.azint_time_s = std::chrono::duration(azint_end_time - azint_start_time).count(); diff --git a/image_analysis/image_preprocessing/ImagePreprocessor.cpp b/image_analysis/image_preprocessing/ImagePreprocessor.cpp index 89452a2a..521b2c06 100644 --- a/image_analysis/image_preprocessing/ImagePreprocessor.cpp +++ b/image_analysis/image_preprocessing/ImagePreprocessor.cpp @@ -70,30 +70,3 @@ ImageStatistics ImagePreprocessor::Analyze(const uint8_t *input, T err_pixel_val } return ret; } - -void ImagePreprocessor::AzimIntegration(const AzimuthalIntegration &integration, AzimuthalIntegrationProfile &profile) { - const auto azint_bins = integration.GetBinNumber(); - std::vector azint_sum(azint_bins); - std::vector azint_sum2(azint_bins); - std::vector azint_count(azint_bins); - - for (int i = 0; i < azint_count.size(); i++) { - azint_sum[i] = 0.0f; - azint_sum2[i] = 0.0f; - azint_count[i] = 0; - } - - auto &pixel_to_bin = integration.GetPixelToBin(); - auto &corrections = integration.Corrections(); - - for (int i = 0; i < npixels; i++) { - const uint16_t bin = pixel_to_bin[i]; - if (bin < azint_bins) { - float val = static_cast(processed_image[i]) * corrections[i]; - azint_sum[bin] += val; - ++azint_count[bin]; - } - } - profile.Clear(integration); - profile.Add(azint_sum, azint_count); -} diff --git a/image_analysis/image_preprocessing/ImagePreprocessor.h b/image_analysis/image_preprocessing/ImagePreprocessor.h index e1caeacc..5ad3bd5d 100644 --- a/image_analysis/image_preprocessing/ImagePreprocessor.h +++ b/image_analysis/image_preprocessing/ImagePreprocessor.h @@ -7,9 +7,7 @@ #include #include "../common/CompressedImage.h" #include "../common/DiffractionExperiment.h" -#include "../common/AzimuthalIntegration.h" #include "../common/PixelMask.h" -#include "../common/AzimuthalIntegrationProfile.h" struct ImageStatistics { size_t error_pixel_count = 0; @@ -33,6 +31,4 @@ public: std::vector &processed_image); ImageStatistics Analyze(const uint8_t *decompressed_image, CompressedImageMode image_mode); - - void AzimIntegration(const AzimuthalIntegration &integration, AzimuthalIntegrationProfile &profile); }; diff --git a/image_analysis/spot_finding/ImageSpotFinder.cpp b/image_analysis/spot_finding/ImageSpotFinder.cpp index 1a35314c..fd561ec9 100644 --- a/image_analysis/spot_finding/ImageSpotFinder.cpp +++ b/image_analysis/spot_finding/ImageSpotFinder.cpp @@ -44,4 +44,34 @@ std::vector ImageSpotFinder::ExtractSpots(const SpotFindingSett return vec; } +void ImageSpotFinder::AzimIntegration(const AzimuthalIntegration &integration, AzimuthalIntegrationProfile &profile) { + const auto azint_bins = integration.GetBinNumber(); + std::vector azint_sum(azint_bins); + std::vector azint_sum2(azint_bins); + std::vector azint_count(azint_bins); + + for (int i = 0; i < azint_count.size(); i++) { + azint_sum[i] = 0.0f; + azint_sum2[i] = 0.0f; + azint_count[i] = 0; + } + + auto &pixel_to_bin = integration.GetPixelToBin(); + auto &corrections = integration.Corrections(); + + if (pixel_to_bin.size() != width * height || corrections.size() != width * height) + throw std::runtime_error("ImageSpotFinder::AzimIntegration: Mismatch in size"); + + for (int i = 0; i < width * height; i++) { + const uint16_t bin = pixel_to_bin[i]; + if (bin < azint_bins) { + float val = static_cast(input_buffer[i]) * corrections[i]; + azint_sum[bin] += val; + ++azint_count[bin]; + } + } + profile.Clear(integration); + profile.Add(azint_sum, azint_count); +} + diff --git a/image_analysis/spot_finding/ImageSpotFinder.h b/image_analysis/spot_finding/ImageSpotFinder.h index e48fd95c..bd6b6833 100644 --- a/image_analysis/spot_finding/ImageSpotFinder.h +++ b/image_analysis/spot_finding/ImageSpotFinder.h @@ -9,6 +9,9 @@ #include "../../common/DiffractionSpot.h" +#include "../common/AzimuthalIntegration.h" +#include "../common/AzimuthalIntegrationProfile.h" + class ImageSpotFinder { protected: const int32_t width, height; @@ -27,6 +30,8 @@ public: virtual ~ImageSpotFinder() = default; virtual std::vector Run(const SpotFindingSettings &settings, const std::vector &res_mask) = 0; + + void AzimIntegration(const AzimuthalIntegration &integration, AzimuthalIntegrationProfile &profile); };