csbdeep-app / scripts /make_example.py
katospiegel's picture
Deploy csbdeep-app as an imaging-plaza Gradio Space (SDSC)
1483ffb verified
Raw
History Blame Contribute Delete
1.1 kB
"""Bake a degraded microscopy image (+ clean ground-truth sidecar) into APP_TMP_DIR.
example.tif — the DEGRADED input (blurred + Poisson/Gaussian noise)
.example_clean.npy — the CLEAN ground truth (leading dot so the validator's
input-picker can't grab it instead of the TIFF)
Run at build time via `python -m scripts.make_example`.
"""
from __future__ import annotations
import numpy as np
import tifffile
from core.io import APP_TMP_DIR, register_protected
from core.synth import clean_image, degrade
def main() -> int:
clean = clean_image(256, 256, seed=0)
deg = degrade(clean, psf_sigma=2.0, peak=40.0, read_sigma=0.03, seed=1)
out = APP_TMP_DIR / "example.tif"
tifffile.imwrite(out, (deg * 65535).astype(np.uint16))
register_protected(out)
np.save(APP_TMP_DIR / ".example_clean.npy", clean.astype(np.float32))
register_protected(APP_TMP_DIR / ".example_clean.npy")
print(f"[make_example] wrote {out} (degraded) + .example_clean.npy (GT)")
return 0
if __name__ == "__main__":
raise SystemExit(main())