Files
Jungfraujoch/image_analysis/roi/ROIIntegration.cpp
T
leonarski_f 58910274bf image_analysis: compute ROI statistics in the non-FPGA path
MXAnalysisWithoutFPGA never filled DataMessage.roi, so ROI integrals were
only available on the FPGA path. Add a software ROI engine that mirrors the
FPGA roi_calc kernel: per-ROI sum, sum of squares, good-pixel count, max and
intensity-weighted centre of mass, with each pixel carrying a 16-bit mask so
it can contribute to any subset of up to 16 ROIs.

New image_analysis/roi/ library (JFJochROIIntegration), structured like azint:
a base that precomputes the per-pixel mask and names, a templated CPU engine
(generic over pixel type for a future 16-bit path), and a GPU kernel using
per-block shared-memory atomics for the STXM case (half-detector ROIs).

Masked pixels are excluded entirely; saturated pixels are excluded from the
sums but still count towards the max, matching roi_calc exactly. The engine is
only constructed when at least one ROI is defined. Downstream CBOR/HDF5 already
consume message.roi, so no further changes are needed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17 21:15:54 +02:00

35 lines
1.2 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "ROIIntegration.h"
#include "../../common/DiffractionExperiment.h"
ROIIntegration::ROIIntegration(const DiffractionExperiment &experiment)
: roi_map(experiment.ExportROIMap()),
width(experiment.GetXPixelsNumConv()),
npixel(roi_map.size()),
roi_count(experiment.ROI().size()),
roi_name(roi_count),
roi_sum(roi_count),
roi_sum2(roi_count),
roi_pixels(roi_count),
roi_x_weighted(roi_count),
roi_y_weighted(roi_count),
roi_max(roi_count) {
for (const auto &[name, id] : experiment.ROI().GetROINameMap())
roi_name[id] = name;
}
void ROIIntegration::Export(std::map<std::string, ROIMessage> &out) const {
for (uint16_t r = 0; r < roi_count; r++)
out[roi_name[r]] = ROIMessage{
.sum = roi_sum[r],
.sum_square = roi_sum2[r],
.max_count = roi_max[r],
.pixels = roi_pixels[r],
.pixels_masked = 0,
.x_weighted = roi_x_weighted[r],
.y_weighted = roi_y_weighted[r],
};
}