Add averaged.html output and document OS support
average-results.py now writes a formatted HTML view alongside averaged.csv, and README documents Linux/macOS requirements plus the Delta-E reference marker. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
42
README.md
42
README.md
@@ -12,8 +12,9 @@ average repeated scans, and relate results to ink mix formulas.
|
|||||||
`auto-scan.sh` runs the whole process in one go:
|
`auto-scan.sh` runs the whole process in one go:
|
||||||
|
|
||||||
1. **Checks required software** — verifies `python3` and ArgyllCMS
|
1. **Checks required software** — verifies `python3` and ArgyllCMS
|
||||||
(`spotread`) are available. Installs python3 via apt and downloads
|
(`spotread`) are available. Installs python3 (via `apt` on Linux or
|
||||||
ArgyllCMS to `~/.local/bin` automatically if missing.
|
Homebrew on macOS) and downloads ArgyllCMS to `~/.local/bin`
|
||||||
|
automatically if missing.
|
||||||
2. **Waits for the instrument** — prompts you to connect the i1Pro 2 via
|
2. **Waits for the instrument** — prompts you to connect the i1Pro 2 via
|
||||||
USB and re-checks until it is detected.
|
USB and re-checks until it is detected.
|
||||||
3. **Scans the samples** — lists the sample names from `samples.txt` in
|
3. **Scans the samples** — lists the sample names from `samples.txt` in
|
||||||
@@ -27,8 +28,9 @@ average repeated scans, and relate results to ink mix formulas.
|
|||||||
`samples.txt`.
|
`samples.txt`.
|
||||||
5. **Updates the averages** — re-averages **all** complete scan CSVs in
|
5. **Updates the averages** — re-averages **all** complete scan CSVs in
|
||||||
the folder into `averaged.csv` (L\*, a\*, b\* mean and standard
|
the folder into `averaged.csv` (L\*, a\*, b\* mean and standard
|
||||||
deviation per sample), then asks whether to rebuild the formula table
|
deviation per sample, plus a `dE00` CIEDE2000 column against the
|
||||||
`formula.csv` (default: yes).
|
reference sample) and a formatted `averaged.html` view, then asks
|
||||||
|
whether to rebuild the formula table `formula.csv` (default: yes).
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
@@ -46,10 +48,27 @@ is built only from scans of the mode you pass (default D50).
|
|||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
- Linux with bash, python3 (auto-installed if missing)
|
### Operating system
|
||||||
|
|
||||||
|
The scripts run on **Linux** and **macOS**:
|
||||||
|
|
||||||
|
- **Linux** — the primary target. Uses `apt` to install python3 if missing
|
||||||
|
and udev rules for USB access (see below). Ships bash 4+.
|
||||||
|
- **macOS** — supported. The default `/bin/bash` is 3.2, so `auto-scan.sh`
|
||||||
|
is written to stay compatible with it; no newer bash is required. python3
|
||||||
|
is installed via [Homebrew](https://brew.sh) if missing, and ArgyllCMS
|
||||||
|
uses the macOS build (runs under Rosetta 2 on Apple Silicon). macOS needs
|
||||||
|
no udev rules. Note: only the desktop workflow is verified on Linux; the
|
||||||
|
macOS paths are portability fixes and have not been hardware-tested.
|
||||||
|
- **Windows** — not supported (no Bourne shell / udev; use WSL instead).
|
||||||
|
|
||||||
|
### Other requirements
|
||||||
|
|
||||||
|
- bash, python3 (auto-installed if missing)
|
||||||
- ArgyllCMS (auto-downloaded to `~/.local/bin/Argyll_V3.4.1` if missing)
|
- ArgyllCMS (auto-downloaded to `~/.local/bin/Argyll_V3.4.1` if missing)
|
||||||
- X-Rite i1Pro 2 with its white calibration tile
|
- X-Rite i1Pro 2 with its white calibration tile
|
||||||
- (Recommended, one time) udev rules so the instrument works without root:
|
- (Linux only, recommended, one time) udev rules so the instrument works
|
||||||
|
without root:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo ./setup-udev.sh
|
sudo ./setup-udev.sh
|
||||||
@@ -67,10 +86,12 @@ cp samples.example.txt samples.txt
|
|||||||
```
|
```
|
||||||
|
|
||||||
Lines starting with `#` are ignored. Material names can be any codes.
|
Lines starting with `#` are ignored. Material names can be any codes.
|
||||||
Mix samples use the pattern `NAME_A+NAME_B[w1 to w2 mix]`, e.g.:
|
Prefix one sample with `*` to mark it as the **Delta-E reference** that the
|
||||||
|
`dE00` column is measured against (if none is marked, the first sample is
|
||||||
|
used). Mix samples use the pattern `NAME_A+NAME_B[w1 to w2 mix]`, e.g.:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
INK_A
|
*INK_A
|
||||||
INK_B
|
INK_B
|
||||||
INK_A+INK_B[75 to 15 mix]
|
INK_A+INK_B[75 to 15 mix]
|
||||||
INK_A+INK_C[30 to 80 mix]
|
INK_A+INK_C[30 to 80 mix]
|
||||||
@@ -86,7 +107,8 @@ discovers the material names automatically from your sample list.
|
|||||||
|------|----------|
|
|------|----------|
|
||||||
| `scan_D50_<timestamp>.tsv` | Raw spotread log (Lab + XYZ + spectrum 380–730 nm) |
|
| `scan_D50_<timestamp>.tsv` | Raw spotread log (Lab + XYZ + spectrum 380–730 nm) |
|
||||||
| `scan_D50_<timestamp>.csv` | Same data as CSV with `sample_id` column |
|
| `scan_D50_<timestamp>.csv` | Same data as CSV with `sample_id` column |
|
||||||
| `averaged.csv` | Per-sample L\*, a\*, b\* mean and std across all scans |
|
| `averaged.csv` | Per-sample L\*, a\*, b\* mean and std, plus `dE00` vs the reference |
|
||||||
|
| `averaged.html` | Formatted view of `averaged.csv` with color swatches |
|
||||||
| `formula.csv` | Averaged Lab plus one percentage column per ink |
|
| `formula.csv` | Averaged Lab plus one percentage column per ink |
|
||||||
| `archive/` | Discarded or superseded scans |
|
| `archive/` | Discarded or superseded scans |
|
||||||
|
|
||||||
@@ -99,7 +121,7 @@ These are used by `auto-scan.sh` but can also be run on their own:
|
|||||||
| `measure.sh [mode]` | Just the spotread measurement session (TSV output) |
|
| `measure.sh [mode]` | Just the spotread measurement session (TSV output) |
|
||||||
| `run-measurement.sh [mode]` | Measurement session + CSV conversion |
|
| `run-measurement.sh [mode]` | Measurement session + CSV conversion |
|
||||||
| `tsv-to-csv.py <tsv> [-s samples.txt]` | Convert a spotread TSV to labelled CSV |
|
| `tsv-to-csv.py <tsv> [-s samples.txt]` | Convert a spotread TSV to labelled CSV |
|
||||||
| `average-results.py <csv...> -o out.csv` | Average Lab across scan CSVs |
|
| `average-results.py <csv...> -o out.csv` | Average Lab across scan CSVs (writes CSV + HTML) |
|
||||||
| `build-formula-table.py` | Rebuild `formula.csv` from the averaged CSV |
|
| `build-formula-table.py` | Rebuild `formula.csv` from the averaged CSV |
|
||||||
| `rebuild-average.sh` | Shortcut for `./auto-scan.sh --average-only` |
|
| `rebuild-average.sh` | Shortcut for `./auto-scan.sh --average-only` |
|
||||||
| `setup-udev.sh` | Install udev rules for USB instrument access (sudo) |
|
| `setup-udev.sh` | Install udev rules for USB instrument access (sudo) |
|
||||||
|
|||||||
@@ -3,14 +3,19 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import csv
|
import csv
|
||||||
|
import html
|
||||||
import math
|
import math
|
||||||
import statistics
|
import statistics
|
||||||
import sys
|
import sys
|
||||||
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
LAB_COLS = ("L*", "a*", "b*")
|
LAB_COLS = ("L*", "a*", "b*")
|
||||||
DE_COL = "dE00"
|
DE_COL = "dE00"
|
||||||
|
|
||||||
|
# D50 / 2 deg white point, used to render approximate sRGB swatches from Lab.
|
||||||
|
WHITE_POINT = (96.422, 100.0, 82.521)
|
||||||
|
|
||||||
# A sample line prefixed with "*" is the Delta-E reference: every other
|
# A sample line prefixed with "*" is the Delta-E reference: every other
|
||||||
# sample's Delta-E is measured against it. The marker is stripped to recover
|
# sample's Delta-E is measured against it. The marker is stripped to recover
|
||||||
# the real sample name.
|
# the real sample name.
|
||||||
@@ -119,6 +124,136 @@ def add_delta_e(rows: list[dict], reference: str | None) -> str | None:
|
|||||||
return ref_id
|
return ref_id
|
||||||
|
|
||||||
|
|
||||||
|
def srgb(L: float, a: float, b: float) -> str:
|
||||||
|
"""Approximate sRGB hex for a CIELAB triple (D50), for display swatches."""
|
||||||
|
fy = (L + 16) / 116
|
||||||
|
fx = fy + a / 500
|
||||||
|
fz = fy - b / 200
|
||||||
|
|
||||||
|
def finv(f):
|
||||||
|
return f**3 if f**3 > 0.008856 else (f - 16 / 116) / 7.787
|
||||||
|
|
||||||
|
X, Y, Z = (finv(f) * w / 100 for f, w in zip((fx, fy, fz), WHITE_POINT))
|
||||||
|
r = 3.1338561 * X - 1.6168667 * Y - 0.4906146 * Z
|
||||||
|
g = -0.9787684 * X + 1.9161415 * Y + 0.0334540 * Z
|
||||||
|
bl = 0.0719453 * X - 0.2289914 * Y + 1.4052427 * Z
|
||||||
|
|
||||||
|
def enc(c):
|
||||||
|
c = max(0.0, min(1.0, c))
|
||||||
|
c = 1.055 * c ** (1 / 2.4) - 0.055 if c > 0.0031308 else 12.92 * c
|
||||||
|
return round(max(0.0, min(1.0, c)) * 255)
|
||||||
|
|
||||||
|
return "#%02x%02x%02x" % (enc(r), enc(g), enc(bl))
|
||||||
|
|
||||||
|
|
||||||
|
def de_bucket(d: float) -> str:
|
||||||
|
if d < 1:
|
||||||
|
return "not perceptible"
|
||||||
|
if d < 2:
|
||||||
|
return "perceptible on close inspection"
|
||||||
|
if d < 3.5:
|
||||||
|
return "perceptible at a glance"
|
||||||
|
return "clearly different"
|
||||||
|
|
||||||
|
|
||||||
|
def write_html(rows: list[dict], ref_used: str | None, path: Path) -> None:
|
||||||
|
"""Write a self-contained HTML view of the averaged results."""
|
||||||
|
has_de = ref_used is not None
|
||||||
|
esc = html.escape
|
||||||
|
|
||||||
|
head_cells = [
|
||||||
|
"<th></th>", "<th>Sample</th>", "<th>n</th>",
|
||||||
|
"<th>L*</th>", "<th>a*</th>", "<th>b*</th>",
|
||||||
|
]
|
||||||
|
if has_de:
|
||||||
|
head_cells.append("<th>ΔE00</th>")
|
||||||
|
|
||||||
|
body_rows = []
|
||||||
|
for r in rows:
|
||||||
|
lab = tuple(float(r[f"{c}_mean"]) for c in LAB_COLS)
|
||||||
|
std = tuple(float(r[f"{c}_std"]) for c in LAB_COLS)
|
||||||
|
is_ref = has_de and r["sample_id"] == ref_used
|
||||||
|
cls = ' class="ref"' if is_ref else ""
|
||||||
|
ref_tag = ' <span class="tag">reference</span>' if is_ref else ""
|
||||||
|
cells = [
|
||||||
|
f'<td><span class="patch" style="background:{srgb(*lab)}"></span></td>',
|
||||||
|
f'<td class="name">{esc(r["sample_id"])}{ref_tag}</td>',
|
||||||
|
f'<td>{esc(str(r["n_scans"]))}</td>',
|
||||||
|
]
|
||||||
|
for m, s in zip(lab, std):
|
||||||
|
cells.append(f'<td>{m:.2f}<span class="std">±{s:.2f}</span></td>')
|
||||||
|
if has_de:
|
||||||
|
d = float(r[DE_COL])
|
||||||
|
de_cls = "de win" if is_ref else ("de bad" if d >= 3.5 else "de")
|
||||||
|
cells.append(f'<td class="{de_cls}" title="{esc(de_bucket(d))}">{d:.2f}</td>')
|
||||||
|
body_rows.append(f' <tr{cls}>{"".join(cells)}</tr>')
|
||||||
|
|
||||||
|
ref_note = (
|
||||||
|
f"ΔE00 is CIEDE2000 against <b>{esc(ref_used)}</b>; "
|
||||||
|
"lower is a closer match."
|
||||||
|
if has_de else
|
||||||
|
"No Delta-E reference was set (mark one sample with a leading '*')."
|
||||||
|
)
|
||||||
|
generated = datetime.now().strftime("%Y-%m-%d %H:%M")
|
||||||
|
|
||||||
|
html_doc = f"""<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Averaged color measurements</title>
|
||||||
|
<style>
|
||||||
|
:root {{ --text:#1f2328; --text2:#57606a; --text3:#8b949e; --stroke:#d0d7de;
|
||||||
|
--bg:#fff; --fill:#f6f8fa; --good:#1a7f37; --bad:#bc4c00; }}
|
||||||
|
* {{ box-sizing:border-box; }}
|
||||||
|
body {{ margin:0; padding:32px 24px 48px; background:var(--bg); color:var(--text);
|
||||||
|
font:14px/1.5 -apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif; }}
|
||||||
|
main {{ max-width:760px; margin:0 auto; }}
|
||||||
|
h1 {{ font-size:22px; margin:0 0 4px; }}
|
||||||
|
.muted {{ color:var(--text2); margin:0 0 20px; }}
|
||||||
|
table {{ border-collapse:separate; border-spacing:0; width:100%;
|
||||||
|
border:1px solid var(--stroke); border-radius:8px; overflow:hidden; }}
|
||||||
|
th,td {{ padding:7px 10px; text-align:right; font-size:13px;
|
||||||
|
font-variant-numeric:tabular-nums; }}
|
||||||
|
th:nth-child(2),td.name {{ text-align:left; }}
|
||||||
|
thead th {{ background:var(--fill); font-size:12px; color:var(--text2);
|
||||||
|
border-bottom:1px solid var(--stroke); }}
|
||||||
|
tbody tr + tr td {{ border-top:1px solid var(--stroke); }}
|
||||||
|
tr.ref td {{ background:var(--fill); }}
|
||||||
|
.patch {{ width:18px; height:18px; display:inline-block; vertical-align:middle;
|
||||||
|
border-radius:5px; border:1px solid var(--stroke); }}
|
||||||
|
.std {{ color:var(--text3); font-size:11px; margin-left:3px; }}
|
||||||
|
.tag {{ font-size:11px; color:var(--text3); border:1px solid var(--stroke);
|
||||||
|
border-radius:4px; padding:0 5px; margin-left:6px; }}
|
||||||
|
.de {{ font-weight:600; }}
|
||||||
|
.win {{ color:var(--good); }}
|
||||||
|
.bad {{ color:var(--bad); }}
|
||||||
|
.faint {{ color:var(--text3); font-size:12px; margin-top:14px; }}
|
||||||
|
@media print {{ body {{ padding:0; }} }}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
<h1>Averaged color measurements</h1>
|
||||||
|
<p class="muted">Per-sample CIELAB means (± standard deviation) across the
|
||||||
|
averaged scans. {ref_note}</p>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>{"".join(head_cells)}</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{chr(10).join(body_rows)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p class="faint">Swatches are sRGB approximations of the measured Lab values
|
||||||
|
(D50 / 2°). Generated by average-results.py on {generated}.</p>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
path.write_text(html_doc, encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
def read_measurements(path: Path, sample_names: list[str]) -> list[dict]:
|
def read_measurements(path: Path, sample_names: list[str]) -> list[dict]:
|
||||||
with path.open(newline="", encoding="utf-8") as f:
|
with path.open(newline="", encoding="utf-8") as f:
|
||||||
rows = list(csv.DictReader(f))
|
rows = list(csv.DictReader(f))
|
||||||
@@ -203,7 +338,11 @@ def main() -> int:
|
|||||||
writer.writeheader()
|
writer.writeheader()
|
||||||
writer.writerows(averaged)
|
writer.writerows(averaged)
|
||||||
|
|
||||||
|
html_path = args.output.with_suffix(".html")
|
||||||
|
write_html(averaged, ref_used, html_path)
|
||||||
|
|
||||||
print(f"Wrote {len(averaged)} averaged sample(s) to {args.output}")
|
print(f"Wrote {len(averaged)} averaged sample(s) to {args.output}")
|
||||||
|
print(f"Wrote HTML view to {html_path}")
|
||||||
if ref_used is not None:
|
if ref_used is not None:
|
||||||
note = "" if reference else " (no '*'-marked sample; using first sample)"
|
note = "" if reference else " (no '*'-marked sample; using first sample)"
|
||||||
print(f"{DE_COL} computed as CIEDE2000 vs {ref_used!r}{note}")
|
print(f"{DE_COL} computed as CIEDE2000 vs {ref_used!r}{note}")
|
||||||
|
|||||||
Reference in New Issue
Block a user