Spaces:
Sleeping
Sleeping
Download code/tests/test_clahe.py from acra-thesis/acra-backend: direct link, hf CLI and curl.
- Browser
- Download file 926 Bytes
-
https://huggingface.co/spaces/acra-thesis/acra-backend/resolve/main/code/tests/test_clahe.py
- Command line
-
hf download hf://spaces/acra-thesis/acra-backend/code/tests/test_clahe.py
-
curl -L -o test_clahe.py https://huggingface.co/spaces/acra-thesis/acra-backend/resolve/main/code/tests/test_clahe.py
926 Bytes
| import numpy as np | |
| from pipeline.clahe import apply_clahe_lab | |
| def _gradient_lab(h: int = 128, w: int = 128) -> np.ndarray: | |
| lab = np.zeros((h, w, 3), dtype=np.float32) | |
| lab[..., 0] = np.linspace(10.0, 90.0, w, dtype=np.float32)[None, :] | |
| lab[..., 1] = 5.0 | |
| lab[..., 2] = -8.0 | |
| return lab | |
| def test_clahe_preserves_ab_channels(): | |
| lab = _gradient_lab() | |
| out = apply_clahe_lab(lab) | |
| np.testing.assert_allclose(out[..., 1:], lab[..., 1:], rtol=0.0, atol=1e-6) | |
| def test_clahe_blended_output_stays_close_to_original(): | |
| lab = _gradient_lab() | |
| out = apply_clahe_lab(lab) | |
| delta = np.abs(out[..., 0] - lab[..., 0]) | |
| assert delta.mean() < 8.0 | |
| assert delta.max() < 25.0 | |
| def test_clahe_uniform_channel_is_unchanged(): | |
| lab = np.full((64, 64, 3), (50.0, 10.0, -5.0), dtype=np.float32) | |
| out = apply_clahe_lab(lab) | |
| np.testing.assert_allclose(out[..., 0], 50.0, rtol=0.0, atol=0.5) | |