beam stop: a bright ring is not a beam stop

Inside the stop a whole ring is blocked, so its own median is blocked too and the per-pixel
comparison has nothing to work with. The walk that covers that case declared a ring to be inside the
stop when its background fell below a third of the LARGEST background of any ring further out - and
on a sample whose background peaks in a strong ring away from the beam, the ordinary background
inside that ring is legitimately below a third of the peak. The walk then runs out to the ring and
returns a filled disk of good detector: on one corpus dataset 16 % of the area, with diffraction
rings plainly visible inside the disk it masked, and on another 2.5 %.

The defect predates the branch; what changed is that the flood from the beam centre used to discard
the disk whenever its seeds landed on invalid pixels, which is how the first of those two datasets
came back with an empty mask instead of a wrong one. Dropping that anchor was right, and it made
this visible.

A ring is now compared against what this detector's background typically is - the median over the
rings the walk is willing to judge - which is robust to a bright ring and to a corner ring of a
handful of pixels alike, and is less code. Evaluated over 151 corpus datasets: the number returning
a disk larger than 0.2 % of the detector falls from 12 to 3, the two pathological cases collapse
(radius 974 -> 68 px and 188 -> 12 px), and genuine stops move by a few pixels at most (152 -> 132,
122 -> 120, 70 -> 64). The new test fails on the old walk and passes on this one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
leonarski_fandClaude Opus 5 committed 2026-09-13 07:36:57 +02:00
1 parent 99910e187e
commit a7ed4e2d34
3 files changed
+65 -19

No files matched your search

+37
View File
@@ -338,3 +338,40 @@ TEST_CASE("ShadowFinder_APolarizedBackgroundIsNotAShadow", "[ShadowFinder]") {
CHECK(mask_for(std::nullopt) > static_cast<long>(W) * H / 20);
}
// Inside the stop a whole ring is blocked, so its own median is blocked too and the per-pixel
// comparison has nothing to work with; the walk that finds those rings is what covers the disk.
// It decides by comparing a ring against what this detector's background typically is - and NOT
// against the brightest ring anywhere further out, which a sample whose background peaks well away
// from the beam turns into a beam stop the size of that peak. The scene here is that: an ordinary
// stop, and a strong ring at four times the background far outside it. What comes back has to be
// the stop, not a disk reaching the ring.
TEST_CASE("ShadowFinder_ABrightRingIsNotABeamStop", "[ShadowFinder]") {
constexpr int RING_R = 100, RING_HALF = 2, RING_LEVEL = 8 * BACKGROUND;
const DiffractionExperiment x = TestExperiment();
const PixelMask pixel_mask(x);
ShadowFinder finder(x, pixel_mask);
std::vector<std::vector<int32_t>> frames;
std::vector<uint8_t> buffer;
for (int f = 0; f < NFRAMES; f++) {
frames.push_back(Scene(/*cross=*/false, /*reflection=*/false));
for (int y = 0; y < H; y++)
for (int xi = 0; xi < W; xi++) {
const double r = std::hypot(xi - C, y - C);
if (std::abs(r - RING_R) <= RING_HALF)
frames.back()[I(xi, y)] = RING_LEVEL;
}
DataMessage msg{};
msg.image = CompressedImage(frames.back(), W, H);
finder.AddImage(msg, buffer);
}
const auto mask = finder.GetMask();
CHECK(mask[I(C, C)] == 1); // the stop is still covered
CHECK(mask[I(C, C - STOP_R - 20)] == 0); // lit detector between the stop and the ring
CHECK(mask[I(C, C - RING_R + 5)] == 0);
CHECK(mask[I(C, C - RING_R)] == 0); // and the ring itself
// Anything much beyond the stop, its arm and their penumbra means the walk ran away.
CHECK(std::count(mask.begin(), mask.end(), 1u) < 6000);
}