Files

74 lines
4.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CdCrop — project notes for Claude
Alex is scanning a large CD collection: two items per flatbed scan, 600 dpi,
5100×7019 RGB BMPs. These tools find each item, straighten and crop it, and
save it as an otherwise unaltered lossless PNG (same mode and DPI, just a
smaller file than BMP). Everything runs locally; no cloud vision services.
## Files
- `cdcrop.py` — the engine, which also runs from the command line (`python cdcrop.py scan.bmp -o out`).
- `cdcrop_ui.py` — the local review interface on 127.0.0.1:8765 (stdlib server and single-page JS). It writes `cdcrop_decisions.csv` to the output folder. Remembers the last-used scans/output folder and settings across restarts (`cdcrop_ui_last.json`). The detail view has a "Context" toggle (shows scan around the crop, darkened outside the boundary) and a "Crop edges" control (manual per-side px push in/out) for covers whose insert isn't quite square — the automatic crop is conservative (sized off whichever corner needs the most trim), so a non-rectangular insert can cost real art at the other corner; the manual push recovers it.
- `cdcrop_tune.py` — fits the angle-choice weights to Alex's picks in the decisions CSV. It saves `cdcrop_tuning.json` only if leave-one-out validation beats the current settings.
- `scanner_calibration.json` — the scanner's geometry correction (see Calibration below).
- `cdcrop_tuning.json` — optional tuned weights; delete it to revert.
## Covers: what Alex wants
- The art is straight, with as much art kept as possible and no scanner lid.
- Rotation uses one Lanczos warp in float, rounded once.
- **Default alignment is the left edge**, unless horizontal lines near the top or bottom argue otherwise.
- Lines that should be parallel to the sides end up parallel.
- Lettering and deliberate borders matter more than blurry photo detail.
- Don't keep out-of-focus art at the edges.
- Borders should look as the artist intended (trim bleed so a frame's border is even).
- He prefers consistent results over chasing slim-margin picks, and wants calibration to his picks over time.
## Discs
The output is a square of side 2(R+6) around the disc; lid showing in the corners is fine.
Orientation rubric:
1. Text-heavy discs: put the text upright.
2. Otherwise: put the label logo upright.
3. Otherwise: center the rim text at the top.
4. A clear photo upright overrides these.
5. Otherwise he doesn't care.
## How it works (engine)
**Finding items**
- The lid is flood-filled using the per-channel gradient max (threshold 2.0 at 1/3 scale).
- Items with circularity ≥ 0.9 are discs.
**Fitting edges (`fit_edge`)**
- Takes the outermost strong peak group, then the innermost line within that group.
- Refines to sub-pixel, then fits a Huber line.
- Soft edges (strength < 6) borrow their angle from another edge.
**Choosing the angle (`angle_components` → `combine_angle`)**
The choice weighs:
- art lines (LSD: verticals first, plus horizontals near the top or bottom);
- the salience of art that would be lost;
- a left-edge bias;
- edge consensus;
- a blur term (`W_BLUR`).
**Calibration**
- Model: scan = M·true, with M = [[1,k],[0,sy]].
- It is measured from two scans of the same item at different angles (SIFT matching plus an affine least-squares fit).
- Analysis runs in true space, and the correction is folded into the final render.
- Alex's calibration: stretch +0.457%, shear −0.105°.
## Status (2026-10-13)
**Results on Alex's 12 reviewed covers:** 9 of 12 picks reproduced within 2 px of drift. The misses:
- DJ C (448_2): out-of-focus art along the top edge; he picks the bottom-edge angle.
- Simple Minds (451_1): trims bleed so the grey border is even. Subtle; likely stays manual.
- Dirty Pretty Things (447_1).
**Blur detector:** compares the ratio of fine to medium detail at the edge with the same ratio 60 px inside.
- It already scales down the "art worth keeping" weight, which fixed DFC.
- An extra cost (`W_BLUR` > 0) breaks other covers, so it defaults to 0. The tuner can try 0, 0.25 and 0.5.
**Open items**
- Flag more of the misses in review.
- Watch the scan folder (deferred until Alex asks).
- Scanner integration (discussed, not started).
Alex runs this from PyCharm on Windows, in its venv (`python -m pip install` the dependencies there).