Download metrics.py from friedeggy/Lab5.1: direct link, hf CLI and curl.
- Browser
- Download file 560 Bytes
-
https://huggingface.co/spaces/friedeggy/Lab5.1/resolve/main/metrics.py
- Command line
-
hf download hf://spaces/friedeggy/Lab5.1/metrics.py
-
curl -L -o metrics.py https://huggingface.co/spaces/friedeggy/Lab5.1/resolve/main/metrics.py
560 Bytes
| import numpy as np | |
| from image_processor import preprocess_image | |
| import config | |
| def compute_mse(original, mosaic): | |
| """ | |
| Compute Mean Squared Error between original and mosaic. | |
| Parameters: | |
| ----------- | |
| original : np.ndarray | |
| Original image | |
| mosaic : np.ndarray | |
| Mosaic image | |
| Returns: | |
| -------- | |
| float : MSE value | |
| """ | |
| # Preprocess image | |
| original = preprocess_image(original, config.mosaic_size) | |
| mse = np.mean((original.astype(float) - mosaic.astype(float)) ** 2) | |
| return mse |