Datasets:
Add the card, previews, loading example, cube index and SHA256SUMS
Browse files- README.md +187 -0
- SHA256SUMS +0 -0
- hardcases-kinds.png +3 -0
- load_example.py +43 -0
- preview.json +7 -0
- preview.py +90 -0
- scrollsim2-scroll.png +3 -0
- scrollsim2-slice.gif +3 -0
- scrollsim2/cubes-test.parquet +3 -0
- scrollsim2/cubes-train.parquet +3 -0
- scrollsim2/cubes-validation.parquet +3 -0
README.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
pretty_name: ScrollSim synthetic scroll tiles
|
| 4 |
+
tags: [vesuvius-challenge, herculaneum, ct, synthetic, segmentation, papyrus]
|
| 5 |
+
size_categories: [10K<n<100K]
|
| 6 |
+
configs:
|
| 7 |
+
- config_name: hardcases-tiles
|
| 8 |
+
data_files:
|
| 9 |
+
- split: train
|
| 10 |
+
path: hardcases-tiles/train-*.parquet
|
| 11 |
+
- split: validation
|
| 12 |
+
path: hardcases-tiles/validation-*.parquet
|
| 13 |
+
- split: test
|
| 14 |
+
path: hardcases-tiles/test-*.parquet
|
| 15 |
+
- config_name: scrollsim2-cubes
|
| 16 |
+
data_files:
|
| 17 |
+
- split: train
|
| 18 |
+
path: scrollsim2/cubes-train.parquet
|
| 19 |
+
- split: validation
|
| 20 |
+
path: scrollsim2/cubes-validation.parquet
|
| 21 |
+
- split: test
|
| 22 |
+
path: scrollsim2/cubes-test.parquet
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
# ScrollSim synthetic scroll tiles
|
| 26 |
+
|
| 27 |
+
Ready-made synthetic CT of rolled papyrus with exact labels: every sheet, every winding number and every inked voxel
|
| 28 |
+
is known, because the scroll was made by code. Use it to train or test sheet detectors, tracers, winding labelers and
|
| 29 |
+
ink models before they meet real scans, where none of this truth exists.
|
| 30 |
+
|
| 31 |
+
**This is not real CT.** Nothing here comes from a scan. A held-apart realism judge still tells these renders from
|
| 32 |
+
real CT almost every time (see [How real it looks](#how-real-it-looks)). A score on this data is model output on
|
| 33 |
+
synthetic data and says nothing about a real scroll until the method is tested on real labels.
|
| 34 |
+
|
| 35 |
+

|
| 36 |
+
|
| 37 |
+

|
| 38 |
+
|
| 39 |
+

|
| 40 |
+
|
| 41 |
+
`preview.json` names the seeds and slice behind the pictures; they were made with `preview.py` from the files here.
|
| 42 |
+
|
| 43 |
+
## What is in it
|
| 44 |
+
|
| 45 |
+
| Part | What | Count | Size |
|
| 46 |
+
| --- | --- | ---: | ---: |
|
| 47 |
+
| `hardcases-tiles` | 2D tiles, 256 x 256: CT, sheet ids, hard-case zone map | 10,000 train, 1,000 validation, 1,000 test | 616 MB |
|
| 48 |
+
| `hardcases-volumes` | 3D blocks, 64 x 256 x 256, one hard case each, 10 kinds x 6 seeds | 60 | 237 MB |
|
| 49 |
+
| `scrollsim2` | whole synthetic scrolls, 256 x 512 x 512, OME-Zarr with pyramid, VC3D-ready surfaces | 8 scrolls plus 2 no-ink twins | 930 MB |
|
| 50 |
+
| `scrollsim2-cubes` | index of every 128^3 chunk of those scrolls holding sheet (one chunk is one ready cube) | 108 train, 12 validation, 48 test | small |
|
| 51 |
+
|
| 52 |
+
About 1.8 GB in all. `SHA256SUMS` covers every file.
|
| 53 |
+
|
| 54 |
+
### Hard Cases tiles
|
| 55 |
+
|
| 56 |
+
Each row of the Parquet shards:
|
| 57 |
+
|
| 58 |
+
| Column | Type | Meaning |
|
| 59 |
+
| --- | --- | --- |
|
| 60 |
+
| `image` | PNG, uint8 | the rendered CT tile |
|
| 61 |
+
| `sheet_id` | PNG, uint16 | sheet center lines, one id per sheet (0 background); a hairpin keeps one id round its fold; spirals get one id per connected piece |
|
| 62 |
+
| `zone` | PNG, uint8 | hard-case bits: fold, contact, delamination, crack, crushed, edge, center (`kit.hardcases.ZONES`) |
|
| 63 |
+
| `air`, `crack` | PNG, uint8 | open air outside the roll; crack openings |
|
| 64 |
+
| `kind` | string | plain, spiral, hairpin, tight_u, tight_bend, accordion, mush, delamination, crack, edge, with `+contact` and `_compact` variants |
|
| 65 |
+
| `plane` | string | `z` (axial) or `y` (side slice) |
|
| 66 |
+
| `seed`, `k` | int | the run seed and tile index: `kit.hardcases.tile(seed, k, 256)` rebuilds the tile |
|
| 67 |
+
| `layout` | JSON | the layout's parameters |
|
| 68 |
+
|
| 69 |
+
### Hard Cases volumes
|
| 70 |
+
|
| 71 |
+
`hardcases-volumes/KIND-SEED.npz`: `ct` (uint8), `sheet` (uint16 thick sheet ids), `lines` (uint16 center lines),
|
| 72 |
+
`zone`, `air`, `crack` (z, y, x = 64, 256, 256), and `layout` (JSON).
|
| 73 |
+
|
| 74 |
+
### ScrollSim v2 scrolls
|
| 75 |
+
|
| 76 |
+
`scrollsim2/SEED-NAME/` is the folder `python -m kit.scrollsim2 make` writes:
|
| 77 |
+
|
| 78 |
+
- `ct.zarr`: OME-Zarr 0.4, uint8, levels 0 to 5, chunks 128^3, scale in micrometers (8 um voxels).
|
| 79 |
+
- `truth/labels.zarr`: uint16, winding number plus 1 per voxel, 0 air; same levels.
|
| 80 |
+
- `truth/contact.zarr/0`: uint8, 0 air, 1 sheet apart from its neighbor, 2 sheet pressed against it.
|
| 81 |
+
- `truth/ink.zarr/0` (ink scrolls): uint8, 1 where ink reaches.
|
| 82 |
+
- `truth/surfaces/spiral-recto/`, `spiral-center/`: the whole sheet as tifxyz, with `winding.npy` per vertex and
|
| 83 |
+
`ink.tif` (ink scrolls).
|
| 84 |
+
- `truth.json`: every parameter, the turns, the center line, the scan model and the render record.
|
| 85 |
+
|
| 86 |
+
| Seed | Name | Scan model | Sheet physics | Ink | Split |
|
| 87 |
+
| --- | --- | --- | --- | --- | --- |
|
| 88 |
+
| 20261126001 | sync-ink | synchrotron | on | yes, plus no-ink twin | train |
|
| 89 |
+
| 20261126002 | sync-ink-crushed | synchrotron, squash 0.35 | on | yes, plus no-ink twin | test |
|
| 90 |
+
| 20261126003 | lab | lab | on | no | train |
|
| 91 |
+
| 20261126004 | plain | none (release-1 look) | off | no | train |
|
| 92 |
+
| 20261126005 | pressed | synchrotron, contact share 0.8 | on | no | train |
|
| 93 |
+
| 20261126006 | joins-cracks | synchrotron, kolleseis and cracks | on | yes | train |
|
| 94 |
+
| 20261126007 | lab-crushed | lab, squash 0.3, warp 8 | on | yes | validation |
|
| 95 |
+
| 20261126008 | sync-ink-small | synchrotron, smaller letters | on | yes | test |
|
| 96 |
+
|
| 97 |
+
Each `scrollsim2/cubes-SPLIT.parquet` row names a scroll and a cube origin (`z0`, `y0`, `x0`, side 128), the
|
| 98 |
+
paths of its arrays, and the cube's sheet share, winding count, pressed share and ink share; `ink_in_ct` is false for
|
| 99 |
+
the no-ink twins, whose ink truth is written but not painted.
|
| 100 |
+
|
| 101 |
+
The no-ink twin has the same seed and parameters with the ink left out of the CT, so a paired ink effect can be
|
| 102 |
+
scored voxel by voxel. Splits are by whole scroll.
|
| 103 |
+
|
| 104 |
+
## Get it
|
| 105 |
+
|
| 106 |
+
```bash
|
| 107 |
+
hf download SharpMeow/scrollsim-tiles --repo-type dataset --local-dir scrollsim-tiles
|
| 108 |
+
cd scrollsim-tiles && sha256sum -c SHA256SUMS
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
Tiles only: add `--include "hardcases-tiles/*"`. One scroll: `--include "scrollsim2/20261126001-sync-ink/*"`.
|
| 112 |
+
|
| 113 |
+
## Load it
|
| 114 |
+
|
| 115 |
+
```python
|
| 116 |
+
import numpy as np, zarr
|
| 117 |
+
from datasets import load_dataset
|
| 118 |
+
from huggingface_hub import snapshot_download
|
| 119 |
+
|
| 120 |
+
# 2D tiles with exact sheet ids
|
| 121 |
+
ds = load_dataset("SharpMeow/scrollsim-tiles", "hardcases-tiles", split="validation")
|
| 122 |
+
row = ds[0]
|
| 123 |
+
img = np.array(row["image"])
|
| 124 |
+
ids = np.array(row["sheet_id"]) # uint16, 0 background
|
| 125 |
+
print(row["kind"], img.shape, "sheets:", len(np.unique(ids)) - 1)
|
| 126 |
+
|
| 127 |
+
# one 128^3 cube of a whole synthetic scroll: CT, winding labels, ink truth
|
| 128 |
+
root = snapshot_download("SharpMeow/scrollsim-tiles", repo_type="dataset",
|
| 129 |
+
allow_patterns=["scrollsim2/20261126001-sync-ink/*"])
|
| 130 |
+
sim = f"{root}/scrollsim2/20261126001-sync-ink"
|
| 131 |
+
cube = (slice(0, 128), slice(128, 256), slice(128, 256))
|
| 132 |
+
ct = zarr.open(f"{sim}/ct.zarr/0", mode="r")[cube]
|
| 133 |
+
winding = zarr.open(f"{sim}/truth/labels.zarr/0", mode="r")[cube].astype(int) - 1 # -1 is air
|
| 134 |
+
ink = zarr.open(f"{sim}/truth/ink.zarr/0", mode="r")[cube]
|
| 135 |
+
print(ct.shape, "windings:", np.unique(winding[winding >= 0]).size, "ink voxels:", int(ink.sum()))
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
`load_example.py` is a runnable version; it was run on this release before upload.
|
| 139 |
+
|
| 140 |
+
## How it was made
|
| 141 |
+
|
| 142 |
+
From [ChaseHendrick/Scrolls](https://github.com/ChaseHendrick/Scrolls) at commit `51a17e6`, on CPU, with fresh seeds
|
| 143 |
+
recorded above and in every file (`20261126xxx`, used by no earlier test in the Scrolls repositories):
|
| 144 |
+
|
| 145 |
+
- **Hard Cases** ([`docs/tools/hardcases.md`](https://github.com/ChaseHendrick/Scrolls/blob/main/docs/tools/hardcases.md)):
|
| 146 |
+
`python -m kit hardcases tiles` with seeds 20261126101 (train), 20261126102 (validation) and 20261126103 (test),
|
| 147 |
+
default kind shares and render; `python -m kit hardcases volume` with seeds 20261126201 to 20261126260. Each layout
|
| 148 |
+
is a continuous 3D field, so every sheet keeps one exact id in any slice direction. The hard-case kinds follow
|
| 149 |
+
Synthetic-Slices v0.2 by vincentl065 ([repository](https://github.com/vincentl065/Synthetic-Slices), MIT), rebuilt
|
| 150 |
+
in 3D.
|
| 151 |
+
- **ScrollSim v2** ([`docs/tools/scrollsim2.md`](https://github.com/ChaseHendrick/Scrolls/blob/main/docs/tools/scrollsim2.md)):
|
| 152 |
+
`python -m kit.scrollsim2 make --surfaces --truth contact` with the settings in each `truth.json`; procedural
|
| 153 |
+
stroke glyphs (`ink_glyphs` `strokes`), so the same parameters rebuild the same scroll on any machine. The glyphs
|
| 154 |
+
are random letter-like shapes chosen by a hash, not text. No texture library: nothing was copied from real CT.
|
| 155 |
+
|
| 156 |
+
## How real it looks
|
| 157 |
+
|
| 158 |
+
Not very, yet. Measured by [simcritic](https://github.com/ChaseHendrick/Scrolls/blob/main/docs/tools/simcritic.md), a
|
| 159 |
+
judge that fits fresh critics to tell real CT windows from simulated ones (0.5: cannot tell; 1.0: always can), on a
|
| 160 |
+
public fragment scan, PHerc0343P, 25 November 2026:
|
| 161 |
+
|
| 162 |
+
| Set | Worst-critic AUC |
|
| 163 |
+
| --- | ---: |
|
| 164 |
+
| Real against real (control) | 0.473 |
|
| 165 |
+
| Hard Cases tiles, render tuned toward that scan, two rounds | 0.999 and 1.000 |
|
| 166 |
+
| The same tiles through a learned sim-to-real texture (not released), five settings | 0.971 to 0.998 |
|
| 167 |
+
|
| 168 |
+
Every simulated set was told apart from real CT. The default Hard Cases render used here scored a linear realism AUC
|
| 169 |
+
of 0.999 against the same scan ([simreal](https://github.com/ChaseHendrick/Scrolls/blob/main/docs/tools/simreal.md)).
|
| 170 |
+
The ScrollSim v2 scrolls were not judged; their tool page says they do not yet look or score like real CT. What gives
|
| 171 |
+
the tiles away most: too much power in the finest spatial frequencies, and grain that is less aligned with the sheets
|
| 172 |
+
than real papyrus fibers.
|
| 173 |
+
|
| 174 |
+
So: good for pretraining, unit tests, debugging and exact per-hard-case scores; not a substitute for real labels.
|
| 175 |
+
A method's rank here is not evidence of its rank on real scrolls.
|
| 176 |
+
|
| 177 |
+
## Notes
|
| 178 |
+
|
| 179 |
+
- Sheet ids and winding numbers are exact by construction; a detector that disagrees is wrong about this data.
|
| 180 |
+
- The scan model's numbers are chosen by eye and from one published setup, not measured; the sheet physics
|
| 181 |
+
amplitudes are guesses.
|
| 182 |
+
- The ink is a simple layer model, not calibrated against real ink; no real ink reader is claimed to see it.
|
| 183 |
+
|
| 184 |
+
## License and credit
|
| 185 |
+
|
| 186 |
+
CC BY 4.0. Synthetic data with no scan data in it, made by the Scrolls kit (code Apache-2.0). Hard-case kinds after
|
| 187 |
+
Synthetic-Slices by vincentl065 (MIT).
|
SHA256SUMS
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
hardcases-kinds.png
ADDED
|
Git LFS Details
|
load_example.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Load the ScrollSim synthetic tiles: one Hard Cases tile, one Hard Cases volume and one 128^3 cube of a scroll.
|
| 2 |
+
|
| 3 |
+
python load_example.py # from the Hub
|
| 4 |
+
python load_example.py --root DIR # from a local copy (hf download ... --local-dir DIR)
|
| 5 |
+
Needs: numpy, pillow, zarr (3), datasets, huggingface_hub.
|
| 6 |
+
"""
|
| 7 |
+
import argparse, glob, json, os
|
| 8 |
+
import numpy as np, zarr
|
| 9 |
+
from datasets import load_dataset
|
| 10 |
+
from huggingface_hub import hf_hub_download, snapshot_download
|
| 11 |
+
|
| 12 |
+
REPO = "SharpMeow/scrollsim-tiles"
|
| 13 |
+
ap = argparse.ArgumentParser()
|
| 14 |
+
ap.add_argument("--root", help="a local copy of the dataset")
|
| 15 |
+
a = ap.parse_args()
|
| 16 |
+
|
| 17 |
+
# 1. a 2D Hard Cases tile with exact sheet ids
|
| 18 |
+
if a.root:
|
| 19 |
+
ds = load_dataset("parquet", data_files=sorted(glob.glob(f"{a.root}/hardcases-tiles/validation-*.parquet")), split="train")
|
| 20 |
+
else:
|
| 21 |
+
ds = load_dataset(REPO, "hardcases-tiles", split="validation")
|
| 22 |
+
row = ds[0]
|
| 23 |
+
img = np.array(row["image"]) # uint8 CT
|
| 24 |
+
ids = np.array(row["sheet_id"]) # uint16, 0 background, one id per sheet
|
| 25 |
+
print("tile:", row["kind"], row["plane"], img.shape, "sheets:", len(np.unique(ids)) - 1)
|
| 26 |
+
|
| 27 |
+
# 2. a 3D Hard Cases block
|
| 28 |
+
name = "hardcases-volumes/hairpin-20261126213.npz"
|
| 29 |
+
path = f"{a.root}/{name}" if a.root else hf_hub_download(REPO, name, repo_type="dataset")
|
| 30 |
+
v = np.load(path)
|
| 31 |
+
print("volume:", json.loads(str(v["layout"]))["kind"], v["ct"].shape, "sheets:", len(np.unique(v["sheet"])) - 1)
|
| 32 |
+
|
| 33 |
+
# 3. one 128^3 cube of a whole synthetic scroll: CT, winding labels, ink truth
|
| 34 |
+
scroll = "scrollsim2/20261126001-sync-ink"
|
| 35 |
+
root = a.root or snapshot_download(REPO, repo_type="dataset", allow_patterns=[f"{scroll}/*"])
|
| 36 |
+
sim = f"{root}/{scroll}"
|
| 37 |
+
cube = (slice(0, 128), slice(128, 256), slice(128, 256))
|
| 38 |
+
ct = zarr.open(f"{sim}/ct.zarr/0", mode="r")[cube]
|
| 39 |
+
winding = zarr.open(f"{sim}/truth/labels.zarr/0", mode="r")[cube].astype(int) - 1 # -1 is air
|
| 40 |
+
ink = zarr.open(f"{sim}/truth/ink.zarr/0", mode="r")[cube]
|
| 41 |
+
print("cube:", ct.shape, "windings:", np.unique(winding[winding >= 0]).size, "ink voxels:", int(ink.sum()))
|
| 42 |
+
assert img.dtype == np.uint8 and ids.dtype == np.uint16 and ct.dtype == np.uint8
|
| 43 |
+
print("ok")
|
preview.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"credit": "Synthetic data made by kit.scrollsim2 and kit.hardcases (ChaseHendrick/Scrolls). No scan data.",
|
| 3 |
+
"scroll_seed": 20261126001,
|
| 4 |
+
"tile_seed": 20261126199,
|
| 5 |
+
"slice_z": 67,
|
| 6 |
+
"command": "python preview.py SIM OUT"
|
| 7 |
+
}
|
preview.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Preview pictures for the ScrollSim tiles dataset (synthetic data only)."""
|
| 2 |
+
import sys, json, numpy as np, zarr, tifffile
|
| 3 |
+
import matplotlib; matplotlib.use("Agg")
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
from matplotlib.colors import ListedColormap
|
| 6 |
+
from scipy import ndimage as ndi
|
| 7 |
+
sys.path.insert(0, "/home/user/Scrolls")
|
| 8 |
+
from kit import hardcases as hc
|
| 9 |
+
from PIL import Image
|
| 10 |
+
|
| 11 |
+
SIM, OUT = sys.argv[1], sys.argv[2]
|
| 12 |
+
PAL = ["#4e79a7", "#f28e2b", "#e15759", "#76b7b2", "#edc948", "#b07aa1", "#ff9da7", "#9c755f", "#59a14f", "#bab0ac"]
|
| 13 |
+
def labcolor(l):
|
| 14 |
+
rgb = np.array([matplotlib.colors.to_rgb(c) for c in PAL])
|
| 15 |
+
out = np.zeros(l.shape + (4,))
|
| 16 |
+
m = l > 0
|
| 17 |
+
out[m, :3] = rgb[(l[m].astype(int) * 7) % len(PAL)]
|
| 18 |
+
out[m, 3] = 0.55
|
| 19 |
+
return out
|
| 20 |
+
|
| 21 |
+
# 1. Hard Cases: one tile per kind, CT above, sheet ids below
|
| 22 |
+
want = ["plain", "spiral", "hairpin", "tight_u", "tight_bend", "accordion", "mush", "delamination", "crack", "edge"]
|
| 23 |
+
got = {}
|
| 24 |
+
k = 0
|
| 25 |
+
while len(got) < len(want) and k < 400:
|
| 26 |
+
r = hc.tile(20261126199, k, 256); k += 1
|
| 27 |
+
base = r["kind"].split("+")[0].replace("_compact", "")
|
| 28 |
+
if base in want and base not in got:
|
| 29 |
+
got[base] = r
|
| 30 |
+
fig, ax = plt.subplots(2, 10, figsize=(20, 4.6), dpi=110)
|
| 31 |
+
for j, name in enumerate(want):
|
| 32 |
+
r = got[name]
|
| 33 |
+
ax[0, j].imshow(r["image"], cmap="gray", vmin=0, vmax=255); ax[0, j].set_title(r["kind"].replace("_", " "), fontsize=10)
|
| 34 |
+
ax[1, j].imshow(r["image"], cmap="gray", vmin=0, vmax=255)
|
| 35 |
+
ax[1, j].imshow(labcolor(ndi.grey_dilation(r["sheet_id"], size=3)))
|
| 36 |
+
for a in ax[:, j]: a.set_axis_off()
|
| 37 |
+
ax[0, 0].text(-20, 128, "CT", rotation=90, va="center", ha="right", fontsize=11)
|
| 38 |
+
ax[1, 0].text(-20, 128, "sheet ids", rotation=90, va="center", ha="right", fontsize=11)
|
| 39 |
+
fig.suptitle("Synthetic: Hard Cases tiles, 256 px, one per kind (seed 20261126199, a preview seed outside every split)", fontsize=12)
|
| 40 |
+
fig.tight_layout(rect=[0, 0, 1, 0.94]); fig.savefig(OUT + "/hardcases-kinds.png"); plt.close(fig)
|
| 41 |
+
|
| 42 |
+
# 2. ScrollSim v2 scroll: axial slice, winding labels, ink truth, and the flattened recto surface
|
| 43 |
+
ct = zarr.open(SIM + "/ct.zarr/0", mode="r"); lb = zarr.open(SIM + "/truth/labels.zarr/0", mode="r")
|
| 44 |
+
ink = zarr.open(SIM + "/truth/ink.zarr/0", mode="r")
|
| 45 |
+
zs = np.asarray(ink[:, ::4, ::4]).sum(axis=(1, 2)); z = int(np.argmax(zs))
|
| 46 |
+
a, l, i3 = ct[z], lb[z], ink[z]
|
| 47 |
+
d = SIM + "/truth/surfaces/spiral-recto"
|
| 48 |
+
X, Y, Zs = (tifffile.imread(f"{d}/{c}.tif").astype(np.float64) for c in "xyz")
|
| 49 |
+
inkt = tifffile.imread(d + "/ink.tif")
|
| 50 |
+
f = 4
|
| 51 |
+
up = lambda g: ndi.zoom(np.nan_to_num(g, nan=-1), f, order=1)
|
| 52 |
+
Xu, Yu, Zu = up(X), up(Y), up(Zs)
|
| 53 |
+
bad = ndi.zoom((X < 0).astype(float), f, order=0) > 0
|
| 54 |
+
vol = np.asarray(ct)
|
| 55 |
+
flat = ndi.map_coordinates(vol.astype(np.float32), [Zu, Yu, Xu], order=1, mode="nearest")
|
| 56 |
+
flat[bad] = np.nan
|
| 57 |
+
inku = ndi.zoom(inkt.astype(float), f, order=0)
|
| 58 |
+
c0 = 0; c1 = min(flat.shape[1], 2600)
|
| 59 |
+
fig = plt.figure(figsize=(16, 9.2), dpi=110)
|
| 60 |
+
g = fig.add_gridspec(2, 3, height_ratios=[1.6, 1])
|
| 61 |
+
for j, (title, ov) in enumerate([("CT, axial slice z %d" % z, None), ("winding labels (exact)", "lab"), ("ink truth (exact)", "ink")]):
|
| 62 |
+
axx = fig.add_subplot(g[0, j]); axx.imshow(a, cmap="gray", vmin=0, vmax=255)
|
| 63 |
+
if ov == "lab": axx.imshow(labcolor(l))
|
| 64 |
+
if ov == "ink":
|
| 65 |
+
m = np.zeros(a.shape + (4,)); m[i3 > 0] = matplotlib.colors.to_rgba("#e15759"); axx.imshow(m)
|
| 66 |
+
axx.set_title(title, fontsize=11); axx.set_axis_off()
|
| 67 |
+
axf = fig.add_subplot(g[1, :])
|
| 68 |
+
show = np.where(np.isnan(flat), 0, flat)[:, c0:c1]
|
| 69 |
+
axf.imshow(show, cmap="gray", vmin=np.nanpercentile(flat, 1), vmax=np.nanpercentile(flat, 99.5), aspect="auto")
|
| 70 |
+
cnt = np.zeros(show.shape + (4,)); edge = inku[:, c0:c1] > 0
|
| 71 |
+
edge = edge & ~ndi.binary_erosion(edge)
|
| 72 |
+
cnt[edge] = matplotlib.colors.to_rgba("#f28e2b"); axf.imshow(cnt, aspect="auto")
|
| 73 |
+
axf.set_title("CT sampled on the recto surface, flattened (inner windings left); orange outlines: ink truth. Synthetic letter-like glyphs, not text", fontsize=11)
|
| 74 |
+
axf.set_axis_off()
|
| 75 |
+
fig.suptitle("Synthetic: one ScrollSim v2 scroll, 256 x 512 x 512, synchrotron scan model, sheet physics and ink (seed 20261126001)", fontsize=12)
|
| 76 |
+
fig.tight_layout(rect=[0, 0, 1, 0.96]); fig.savefig(OUT + "/scrollsim2-scroll.png"); plt.close(fig)
|
| 77 |
+
|
| 78 |
+
# 3. slow GIF: CT, then labels, then ink, on the axial slice
|
| 79 |
+
frames = []
|
| 80 |
+
base = np.stack([a] * 3, -1).astype(np.float32)
|
| 81 |
+
def blend(rgba):
|
| 82 |
+
o = base.copy(); al = rgba[..., 3:4]; o = o * (1 - al) + rgba[..., :3] * 255 * al; return Image.fromarray(o.astype(np.uint8))
|
| 83 |
+
frames.append(Image.fromarray(base.astype(np.uint8)))
|
| 84 |
+
frames.append(blend(labcolor(l)))
|
| 85 |
+
m = np.zeros(a.shape + (4,)); m[i3 > 0] = matplotlib.colors.to_rgba("#e15759"); frames.append(blend(m))
|
| 86 |
+
frames = [fr.resize((768, 768), Image.NEAREST) for fr in frames]
|
| 87 |
+
frames[0].save(OUT + "/scrollsim2-slice.gif", save_all=True, append_images=frames[1:], duration=[6000, 6000, 6000], loop=0, optimize=True)
|
| 88 |
+
json.dump({"credit": "Synthetic data made by kit.scrollsim2 and kit.hardcases (ChaseHendrick/Scrolls). No scan data.", "scroll_seed": 20261126001, "tile_seed": 20261126199, "slice_z": z,
|
| 89 |
+
"command": "python preview.py SIM OUT"}, open(OUT + "/preview.json", "w"), indent=1)
|
| 90 |
+
print("z", z, "ok")
|
scrollsim2-scroll.png
ADDED
|
Git LFS Details
|
scrollsim2-slice.gif
ADDED
|
Git LFS Details
|
scrollsim2/cubes-test.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:919e16a39ba50727642fa5e06c7911ffd47f362c3febc7637c880303c571073c
|
| 3 |
+
size 8135
|
scrollsim2/cubes-train.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b1ad0a9922dd0811811528c9cb3fcea5e26a0c5eb82f82037a329d2f12fd52be
|
| 3 |
+
size 9044
|
scrollsim2/cubes-validation.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a72c745317f841d8ea8e595f73950ff253611168c0bc135bffde653aeda0b206
|
| 3 |
+
size 7422
|