SqueezeToRawGeometry: an assembled JUNGFRAU image back to raw module frames
The inverse of TransferModuleAdjustMultipixels: a raw pixel is the sum of the 2 (multipixel) or 4 (chip corner) assembled pixels its value was split over, as the split conserves the count; an error pixel among them makes it an error pixel, a saturated one or a sum past the destination's range a saturated one. ConvertedToRawGeometry takes one of them instead, which is right for masks and maps but halves the counts of the split pixels. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UqXYdHHZ4cogS1mrGUtfN7
This commit is contained in:
1 parent
69948cb151
commit
65a3e05463
3 files changed
+97
No files matched your search
@@ -8,6 +8,18 @@
|
||||
#include "Coord.h"
|
||||
#include "DiffractionExperiment.h"
|
||||
|
||||
// An assembled image back to raw module frames, the multipixels summed (SqueezeMultipixelsToModule)
|
||||
template<class Td, class Ts>
|
||||
void SqueezeToRawGeometry(const DiffractionExperiment &experiment, Td *destination, const Ts *source,
|
||||
Ts min, Ts max, Td dest_min, Td dest_max) {
|
||||
for (size_t module_number = 0; module_number < experiment.GetModulesNum(); module_number++)
|
||||
SqueezeMultipixelsToModule<Td, Ts>(destination + module_number * RAW_MODULE_SIZE, source,
|
||||
experiment.GetModuleSlowDirectionStep(module_number), min, max,
|
||||
dest_min, dest_max,
|
||||
experiment.GetModuleFastDirectionStep(module_number),
|
||||
experiment.GetPixel0OfModuleConv(module_number));
|
||||
}
|
||||
|
||||
// Input coord is column + 1024 * (line + 512 * module)
|
||||
// Copies result over multipixel - can be used for example for mask calculation
|
||||
template<class Td, class Ts>
|
||||
|
||||
@@ -139,6 +139,56 @@ void TransferModuleAdjustMultipixels(Td *destination, const Ts *source, int64_t
|
||||
}
|
||||
}
|
||||
|
||||
// Inverse of TransferModuleAdjustMultipixels: each raw pixel of the module is the sum of the pixels its value was
|
||||
// split over (2 for a multipixel, 4 at a chip corner), as the split conserves the count. A raw pixel is an error
|
||||
// pixel where any of them is at or below min, saturated where any is at or above max or the sum reaches dest_max.
|
||||
template<class Td, class Ts>
|
||||
void SqueezeMultipixelsToModule(Td *destination, const Ts *source, int64_t slow_dir_step, Ts min, Ts max,
|
||||
Td dest_min, Td dest_max, int64_t fast_dir_step = 1, int64_t offset_0 = 0) {
|
||||
for (int64_t line = 0; line < RAW_MODULE_LINES; line++) {
|
||||
int64_t y[2] = {line + ((line > 255) ? 2 : 0), -1};
|
||||
if (line == 255)
|
||||
y[1] = 256;
|
||||
else if (line == 256)
|
||||
y[1] = 257;
|
||||
|
||||
for (int64_t col = 0; col < RAW_MODULE_COLS; col++) {
|
||||
const int64_t chip = col / 256, i = col % 256;
|
||||
int64_t x[2] = {i + chip * 258, -1};
|
||||
if ((i == 255) && (chip < 3))
|
||||
x[1] = x[0] + 1;
|
||||
else if ((i == 0) && (chip > 0))
|
||||
x[1] = x[0] - 1;
|
||||
|
||||
int64_t sum = 0;
|
||||
bool error = false, saturated = false;
|
||||
for (int64_t yy: y) {
|
||||
for (int64_t xx: x) {
|
||||
if ((yy < 0) || (xx < 0))
|
||||
continue;
|
||||
const Ts v = source[offset_0 + yy * slow_dir_step + xx * fast_dir_step];
|
||||
if (v <= min)
|
||||
error = true;
|
||||
else if (v >= max)
|
||||
saturated = true;
|
||||
else
|
||||
sum += v;
|
||||
}
|
||||
}
|
||||
|
||||
Td &out = destination[line * RAW_MODULE_COLS + col];
|
||||
if (error)
|
||||
out = dest_min;
|
||||
else if (saturated || (sum >= dest_max))
|
||||
out = dest_max;
|
||||
else if (sum <= dest_min)
|
||||
out = dest_min + 1;
|
||||
else
|
||||
out = static_cast<Td>(sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void LineConvtToRaw(T *destination, const T *source, size_t fast_direction_step) {
|
||||
for (int chip = 0; chip < 4; chip++) {
|
||||
|
||||
@@ -517,3 +517,38 @@ TEST_CASE("RawToConvertedCoordinate_Coord","[RawToConvertedGeometry]") {
|
||||
REQUIRE(Catch::Approx(c.x) == CONVERTED_MODULE_COLS + 8 + 800.5 + 6); // col 800 becomes 806 due to 3 chip boundaries
|
||||
REQUIRE(Catch::Approx(c.y) == CONVERTED_MODULE_LINES * 2 + 36 - 1 - 300.25 - 2); // line 300 becomes 302 due to 1 chip boundary
|
||||
}
|
||||
|
||||
TEST_CASE("RawToConvertedGeometry_SqueezeToRawGeometry","[RawToConvertedGeometry]") {
|
||||
// Assembled with the multipixels split, then squeezed back: the raw frames, where the split divides evenly
|
||||
DiffractionExperiment x(DetJF(4, 2, 8, 36, true));
|
||||
x.PixelSigned(true).BitDepthImage(16);
|
||||
|
||||
std::vector<int16_t> raw(x.GetModulesNum() * RAW_MODULE_SIZE);
|
||||
for (size_t i = 0; i < raw.size(); i++)
|
||||
raw[i] = static_cast<int16_t>(4 * (i % 5000) - 400);
|
||||
raw[255 * RAW_MODULE_COLS + 255] = INT16_MIN; // error, chip corner
|
||||
raw[RAW_MODULE_SIZE + 10 * RAW_MODULE_COLS + 256] = INT16_MAX; // saturated, multipixel
|
||||
|
||||
std::vector<int32_t> image(x.GetPixelsNum(), INT32_MIN);
|
||||
for (int m = 0; m < x.GetModulesNum(); m++)
|
||||
TransferModuleAdjustMultipixels<int32_t, int16_t>(image.data(), raw.data() + m * RAW_MODULE_SIZE,
|
||||
x.GetModuleSlowDirectionStep(m), INT16_MIN, INT16_MAX,
|
||||
x.GetModuleFastDirectionStep(m), x.GetPixel0OfModuleConv(m));
|
||||
for (auto &v: image) {
|
||||
if (v == INT16_MIN)
|
||||
v = INT32_MIN;
|
||||
else if (v == INT16_MAX)
|
||||
v = INT32_MAX;
|
||||
}
|
||||
|
||||
std::vector<int16_t> squeezed(raw.size());
|
||||
SqueezeToRawGeometry<int16_t, int32_t>(x, squeezed.data(), image.data(), INT32_MIN, INT32_MAX,
|
||||
INT16_MIN, INT16_MAX);
|
||||
CHECK(squeezed == raw);
|
||||
|
||||
// A sum past the 16-bit range is saturated
|
||||
image[x.GetPixel0OfModuleConv(0)] = 40000;
|
||||
SqueezeToRawGeometry<int16_t, int32_t>(x, squeezed.data(), image.data(), INT32_MIN, INT32_MAX,
|
||||
INT16_MIN, INT16_MAX);
|
||||
CHECK(squeezed[0] == INT16_MAX);
|
||||
}
|
||||
Reference in new issue
Block a user