Files
Jungfraujoch/image_analysis/azint/AzIntEngineCPU.h
T
leonarski_fandClaude Opus 5 5830f78d57 Revert the azimuthal-integration sigma clip
Removes azim_int_settings.sigma_clip / rugnux --azim-sigma-clip and the clipping
machinery in AzIntEngine. This is a partial revert of a6be35ccd - the ice-ring-mask
removal that commit also carried stays. Sigma clipping remains where it started and
where it is needed: inside the adaptive spot finder, at a fixed 3 sigma on raw
counts, feeding the detection threshold and the ice score.

The option made the workflow harder to reason about than the quantity was worth. It
gave azimuthal integration two meanings behind one setting - the bin mean and the
background under the peaks - which the azimuthal-integration workflows do not need.
It also did not compose with the fused GPU engine, which supplies the profile from
its PLAIN pass: on the default rugnux, viewer and receiver path the setting was
silently doing nothing (measured, the profile came out identical to the unclipped
run to 1e-6 with identical per-bin pixel counts). Making it correct is not a matter
of gating that one shortcut - it means separating the workflows (azimuthal
integration, MX rotation, MX stills, geometry calibration) and deciding per workflow
what the profile is for, which is a larger change than the option earns.

The default path is unaffected: over 20 images of a rotation dataset the radial
profile, the per-bin pixel counts and the spot counts are unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 15:31:19 +02:00

56 lines
2.0 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <limits>
#include <type_traits>
#include "AzIntEngine.h"
class AzIntEngineCPU : public AzIntEngine {
public:
// image is anything that can be referenced with operator[]
template <class T>
void RunAzint(const T &image, AzimuthalIntegrationProfile &profile) {
for (int i = 0; i < azint_count.size(); i++) {
azint_sum[i] = 0.0f;
azint_sum2[i] = 0.0f;
azint_count[i] = 0;
}
if (image.size() != npixel)
throw std::runtime_error("ImageSpotFinder::AzimIntegration: Mismatch in size");
const uint16_t *pixel_to_bin = integration.GetPixelToBin().data();
const float *corrections = integration.Corrections().data();
using pixel_t = std::remove_cv_t<std::remove_reference_t<decltype(image[0])>>;
for (int i = 0; i < image.size(); i++) {
const pixel_t v = image[i];
// saturated pixels use the type's max value; for signed types
// masked/bad pixels additionally use the min value
if (v == std::numeric_limits<pixel_t>::max())
continue;
if constexpr (std::is_signed_v<pixel_t>) {
if (v == std::numeric_limits<pixel_t>::min())
continue;
}
const float val = static_cast<float>(v) * corrections[i];
const float val_sq = val * val;
const uint16_t bin = pixel_to_bin[i];
if (bin < azint_bins) {
azint_sum[bin] += val;
azint_sum2[bin] += val_sq;
++azint_count[bin];
}
}
profile.Clear(integration);
profile.Add(azint_sum, azint_sum2, azint_count);
}
AzIntEngineCPU(const AzimuthalIntegrationMapping& integration);
void Run(const ImagePreprocessorBuffer &image, AzimuthalIntegrationProfile &profile) override;
};