# L2 Local focus versus field focus

Status: exploratory measurement on original TIFF pixels. Reproduce with `PYTHONDONTWRITEBYTECODE=1 python3 research/l2_focus.py`. The [per-mark table](../results/l2/focus-scores.csv) includes every score, the focus plane at which the user clicked, and the field-wide and local peak planes. Plane indices are zero-based.

For each of the 54 provisional possible-diatom clicks, measure the RMS difference from a Gaussian-blurred version of a 96 × 96 pixel crop centered on the click, clipped at field edges. Apply the same score to the entire 768 × 768 field. Read every plane from the source TIFF. The point near an edge may have a smaller crop. This uses the full stack retrospectively and does not simulate an active focus request.

The local maximum occurs on a different plane from the field maximum for 40 of 54 marks. In 24 of 54 it differs by more than one plane. The fields were chosen for practice, include two fields not marked complete, and contain nonexpert observations. The crop can include multiple objects and debris. Contrast is a focus proxy and a higher score may reflect sharper debris or an irrelevant feature. These numbers show opportunities for local focus selection, not improved identification or a count of missed valves.

Next compare cropped focal planes side by side with an analyst, including a few cases where the local and field peaks disagree. Test a realistic policy using only the planes already acquired and score whether the added image changes identification. Include crossing objects whose local crops overlap.

## Point-prompt masks at local contrast peak · 2026-11-30

For all 14 marks flagged as crossings, compare the existing single-point MobileSAM mask at the plane recorded with the click against a mask generated from the same XY point at the local contrast maximum calculated above. For the one mark whose planes agree, reuse the same mask; the other 13 are new inferences. [Inspect every pair](/results/l2/focused-masks.html); [download coordinates and comparisons](/results/l2/focused-masks.json). The full-size local-focus masks are saved alongside the results and the original masks remain in R6. This is an oracle point experiment: the analyst supplied the prompt and there is no automatic detection.

Among the 13 changed-plane pairs, the median spatial mask IoU is 0.695 (range 0.190–0.938). This is agreement between two model outputs, **not** accuracy against a reference. Both predicted masks sometimes merge neighbors or highlight debris. In one crowded example (GC108240a mark 29), the alternative plane visibly narrows a broad multi-object mask to a single-looking valve; another example (GC104889a mark 10) expands onto surrounding material. Neither visual impression establishes the target identity without expert review.

The focus score searches the whole acquired stack at a fixed XY, whose 96-pixel neighborhood can contain multiple valves and background. Brightfield focus response and stack registration can vary with Z, and the plane stored with a click need not represent a deliberate best-focus selection. Some output extends outside the displayed crop; inspect the saved full-field masks before judging. Testing whether local focus selection actually improves instance recovery requires independent expert-marked targets and contours or count judgments, alongside alternatives including field focus and an analyst-selected plane. Record any changes in identification and review time, and never silently replace the recorded plane with the contrast maximum.

Reproduce with `YOLO_CONFIG_DIR=/tmp/diatom-yolo-config MPLCONFIGDIR=/tmp/mpl-diatom /tmp/diatom-research-venv/bin/python research/l2_focused_masks.py`; requires the R6 masks, focus-score CSV and `/tmp/mobile_sam.pt`.
