#20 - Calibrate measures the film's base, and the gaps are found by it #21

Merged
eliott merged 7 commits from feat/20-film-base into main 2026-11-17 22:56:02 +01:00
Owner

This sits on top of #8 (the live view): merge #8 first. Until then the diff here also shows #8's commits; this pull request's own are the ones marked "Part of #20".

Calibrate now starts by measuring how clear this film's bare base is, and the scanner finds the gaps between frames by that measure instead of guessing it from each picture. Show it a blank frame, or draw a rectangle on the live view inside a gap (for film that came back from the lab already cut), or skip and let the scan learn it from the frames it finds.

A calibration is now made for one film. On thin negatives that the scanner could not center before, three frames that had each failed were centered once the base was measured.

Closes #20

How it works

  • Three sources for the base, from the surest to the least: measured in a whole blank frame (level, grain, and how the light falls off across the picture), measured in a rectangle picked by hand (level and grain), or learned during the scan from the gaps beside each frame found with both its edges (median of the last 5).
  • The detector with a measure: a gap column is within 0.04 of the measured level (column by column where a blank frame gave the light's falloff) and at most max(0.02, 1.5 x grain) uneven. The limit never goes under the 0.02 used without a measure.
  • A measure refuses what is not bare film: a blank frame with a picture in it, a rectangle that runs into a picture. A speck of dust in a rectangle is allowed (9 columns in 10 must be bare; level and grain are medians).
  • Out of date: nothing on a film is clearer than its base, so a picture more than 0.04 brighter than the measured base means the measure is another film's (or the exposure or lamp changed). The scan pauses and asks; it goes on with a guess only on a yes. A picture all darker than the base is not taken as a sign: a dense frame with no gap in view looks the same.
  • Where the step lives: the measure is its own request (POST /api/film-base, DELETE to forget it), kept by the session until the next Calibrate, which writes it into calibration.json with the roll's name. It can't be part of the calibration's own looks: those need a picture in view, a blank frame has none.
  • The live marks use the measure with the grain of a single frame (the measure is made in the mean of 5).
  • Photos are read without the measure: a photo's tones are not the live view's.

Tested

  • cargo test: 255 passed.
  • tools/parity.py: SAME. The Python reference has no measured base: the check compares the detector as it guesses the base, which this leaves as it was.
  • On the real scanner (X-T5 through its live view, 35mm negative, thin frames): Calibrate with the film's base measured, then a scan of three frames that had each failed to be found before. All three were centered. Which of the two ways the base was measured in (blank frame or rectangle) was not noted.

Not tested

  • On the real scanner: whichever of the blank frame and the drawn rectangle was not used above; Skip (the base learned during the scan); the pause when the measure is out of date; a measure being refused.
  • A camera without a live view (no rectangle can be drawn there: blank frame or skip).
  • Slides, 120 film, panoramic frames.
  • The page was not run in a browser by anything automated: only the server and the session behind it are covered by tests.
  • Windows and macOS.

Docs

  • docs/frame-detection.md (the three ways the base is known, the measure, when it is out of date, how it is learned), docs/build-guide.md (Calibrate in two steps, for each film, manual exposure), docs/troubleshooting.md (the three new messages), docs/how-it-works.md and the README.

Changes in behaviour

  • One calibration for each film. A scan is refused ("Calibrate for this film first") when the calibration was not made for the roll's name. Calibrations made before this are refused once: calibrate again.
  • Calibrate takes two steps in the app: the film's base (or Skip), then the frame.
  • rollscan calibrate on the command line neither measures the base nor records the roll: a calibration made there is refused by a scan started from the app. rollscan scan itself is unchanged.
  • Manual exposure is now needed from the calibration to the end of the scan, where a measure was made.
**This sits on top of #8 (the live view): merge #8 first.** Until then the diff here also shows #8's commits; this pull request's own are the ones marked "Part of #20". Calibrate now starts by measuring how clear this film's bare base is, and the scanner finds the gaps between frames by that measure instead of guessing it from each picture. Show it a blank frame, or draw a rectangle on the live view inside a gap (for film that came back from the lab already cut), or skip and let the scan learn it from the frames it finds. A calibration is now made for one film. On thin negatives that the scanner could not center before, three frames that had each failed were centered once the base was measured. Closes #20 ## How it works - **Three sources for the base**, from the surest to the least: measured in a whole blank frame (level, grain, and how the light falls off across the picture), measured in a rectangle picked by hand (level and grain), or learned during the scan from the gaps beside each frame found with both its edges (median of the last 5). - **The detector with a measure**: a gap column is within 0.04 of the measured level (column by column where a blank frame gave the light's falloff) and at most `max(0.02, 1.5 x grain)` uneven. The limit never goes under the 0.02 used without a measure. - **A measure refuses what is not bare film**: a blank frame with a picture in it, a rectangle that runs into a picture. A speck of dust in a rectangle is allowed (9 columns in 10 must be bare; level and grain are medians). - **Out of date**: nothing on a film is clearer than its base, so a picture more than 0.04 brighter than the measured base means the measure is another film's (or the exposure or lamp changed). The scan pauses and asks; it goes on with a guess only on a yes. A picture all darker than the base is not taken as a sign: a dense frame with no gap in view looks the same. - **Where the step lives**: the measure is its own request (`POST /api/film-base`, `DELETE` to forget it), kept by the session until the next Calibrate, which writes it into `calibration.json` with the roll's name. It can't be part of the calibration's own looks: those need a picture in view, a blank frame has none. - **The live marks** use the measure with the grain of a single frame (the measure is made in the mean of 5). - **Photos are read without the measure**: a photo's tones are not the live view's. ## Tested - `cargo test`: 255 passed. - `tools/parity.py`: SAME. The Python reference has no measured base: the check compares the detector as it guesses the base, which this leaves as it was. - On the real scanner (X-T5 through its live view, 35mm negative, thin frames): Calibrate with the film's base measured, then a scan of three frames that had each failed to be found before. All three were centered. Which of the two ways the base was measured in (blank frame or rectangle) was not noted. ## Not tested - On the real scanner: whichever of the blank frame and the drawn rectangle was not used above; **Skip** (the base learned during the scan); the pause when the measure is out of date; a measure being refused. - A camera without a live view (no rectangle can be drawn there: blank frame or skip). - Slides, 120 film, panoramic frames. - The page was not run in a browser by anything automated: only the server and the session behind it are covered by tests. - Windows and macOS. ## Docs - `docs/frame-detection.md` (the three ways the base is known, the measure, when it is out of date, how it is learned), `docs/build-guide.md` (Calibrate in two steps, for each film, manual exposure), `docs/troubleshooting.md` (the three new messages), `docs/how-it-works.md` and the README. ## Changes in behaviour - **One calibration for each film.** A scan is refused ("Calibrate for this film first") when the calibration was not made for the roll's name. Calibrations made before this are refused once: calibrate again. - **Calibrate takes two steps** in the app: the film's base (or Skip), then the frame. - **`rollscan calibrate` on the command line** neither measures the base nor records the roll: a calibration made there is refused by a scan started from the app. `rollscan scan` itself is unchanged. - **Manual exposure is now needed** from the calibration to the end of the scan, where a measure was made.
The same work as before (0006fa0, 615ce2d), put back on top of the Rollscan
rename after it was taken out of main.
To look at the film the scanner waits for the live view to stop changing, then
averages five frames: no shot is taken to center a frame or to calibrate.

The shot that is kept is checked. Found more than 8 px off-center, the film is
corrected by what the shot shows and the shot is taken once more. How far the
shots come out from the live view is learned from them, and the next frames are
aimed accordingly. A frame lined up by hand is shot where it was put.

A calibration records whether it was measured through the live view or in
shots, and is only used the way it was made.
Between a gap and the picture, a live view can show a few columns as bright
as the base but too uneven to belong to the gap. The four columns probed
just outside the bright run then fell on that fringe, the dense picture
right after it was never seen, and no frame was found.

The probe now reaches up to 8 columns further out, and the edge is put at
the first dense column it finds.
On a thin negative a frame can start as clear as the base: the gap before it
is seen, the previous frame's dense end too, but this frame's own edge shows
nothing and no frame was found.

When a frame's dense edge borders a bright band on one side only, and from
that edge to the band's other end is a gap's width (within 25%), the band is
the gap and the other frame starts at its other end. Such an edge is only
ever good for a lone reading (partial, near the center, agreeing with the
others), and nothing is worked out from it in turn.
A gap with dense picture on both sides, a gap's width apart, placed the frame
correctly, but an edge inside the picture (where it turns as clear as the
base) put it somewhere else, and with two lone readings that disagree no
frame was found.

A lone reading from a gap seen from both sides now outweighs the others.
In a live view the bare base is close to too uneven to count as a gap, and a
speck of dust on it makes a few columns more so. From one picture to the next
a gap was cut in two, and when the piece left next to the frame was too
narrow to count, the frame's edge was lost.

A break of at most 6 columns, all as bright as the base and no more uneven
than 0.04, no longer cuts a bright run in two.
The frame and gap widths came from the motor: pixels a step, times the
drive's steps a millimetre on paper. On the real scanner that put the frame
1 to 2.5% too narrow, and a frame placed by one edge up to 10 px off center.

The pressure frame's window is exactly as tall as a frame, so the film's
height in the picture gives the pixels in a millimetre directly: 24 mm for
35mm film, standard or panoramic, 56 mm for 120. Each format's own length
then gives its frame and its gap. The motor's scale stays as the cross-check
and the fallback: it is used when the two are more than 10% apart, or the
window's top or bottom isn't in the picture.
A look at the film through the live view waits for 8 frames in a row that
differ by almost nothing. The limit, 0.01 in a column's mean brightness, is
crossed by a sideways shake of 0.02 px at the window's edge: in a room that
shakes the camera by a tenth of a pixel the picture never came to rest, and
calibration and scans stopped with that error.

The limit is now 0.1. Film that is still moving goes by whole pixels between
two frames and changes a column by far more.
The bare base's level was that of the brightest hundredth of the columns. A
camera sharpens its live view and leaves a column or two brighter than
anything on the film beside every sharp dark edge: the window's, and each
dense bar in a picture. With enough of them the level was set by fringes,
the real gaps came out just too dark to count, and no gap was found at all.

The level is now taken once lines thinner than 9 columns are taken out.
The detector guessed the base's level from each picture's brightest columns,
and allowed a gap a fixed unevenness set on still photos. The base can now be
measured on the film being scanned: in a whole unexposed frame (its level,
its grain, and how the light falls off across the picture), or in a part of
the picture picked by hand, such as a gap (level and grain).

A calibration is made for one film and carries its base. With it a gap is a
column near the measured level and about as grainy as measured. Without it
the base is learned from the gaps of the frames a scan finds with both their
edges. When the film shows something clearly brighter than the measured
base, the measure is not this film's: the scan asks before going on with a
guess.

Part of #20
Calibrate now opens under the picture: measure the base in a blank frame, in
a rectangle drawn on the live view inside a gap, or skip and let the scan
learn it. Then, with a frame in view, calibrate.

The page says when the calibration was made for another film, shows whether
the base was measured or is learned, and when a scan finds the measure out
of date asks before it goes on with a guess.

Part of #20
Part of #20
Part of #20
The fixes made to the detector for the live view were not made in the Python
it was ported from, and tools/parity.py found the two apart on one picture
(a slide read from a JPEG, half a pixel). The reference now takes the base's
level without the thin bright lines, bridges short breaks in a gap, looks
past a soft fringe for a frame's edge, takes a gap-wide run after a frame's
dense end for the gap, and believes a gap seen from both sides first.

tools/parity.py: SAME.
The live view fixes were only in the table of knobs. Also: the frame's width
comes from the film's height (how-it-works), what has been run on the real
scanner (README), and a camera that shakes (troubleshooting).
Part of #20
eliott merged commit d17eac5b89 into main 2026-11-17 22:56:02 +01:00
eliott deleted branch feat/20-film-base 2026-11-17 22:56:02 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
RollNote/rollscan!21
No description provided.