noise2void-app / scripts /make_example.py
katospiegel's picture
Deploy noise2void-app as an imaging-plaza Gradio Space (SDSC)
bb75e0a verified
Raw
History Blame Contribute Delete
1.2 kB
"""Bake a synthetic noisy image + clean ground-truth sidecar into APP_TMP_DIR.
The clean image is the ground truth so the blind-spot denoiser can be scored with
PSNR / SSIM. Noise2Void itself never sees the clean image — it denoises the noisy
input alone — but we keep the clean copy for evaluation.
"""
from __future__ import annotations
import sys
import numpy as np
import tifffile
from core.io import APP_TMP_DIR, register_protected
from core.synth import add_noise, clean_image
def main() -> int:
clean = clean_image(H=256, W=256, seed=7)
noisy = add_noise(clean, sigma=0.13, seed=7)
out = APP_TMP_DIR / "example.tif"
# Single-page noisy TIFF the user/API sees. The clean ground truth is kept as a
# hidden sidecar (leading dot) so it isn't picked up as an input but is still
# available for PSNR/SSIM scoring.
tifffile.imwrite(out, (noisy * 255).astype("uint8"))
np.save(APP_TMP_DIR / ".example_clean.npy", clean) # ground-truth sidecar
register_protected(out)
register_protected(APP_TMP_DIR / ".example_clean.npy")
print(f"wrote {out} shape={noisy.shape}")
return 0
if __name__ == "__main__":
sys.exit(main())