Spaces:
Paused
Paused
Download utils/validation.py from MBG0903/Saree-Design-App: direct link, hf CLI and curl.
- Browser
- Download file 630 Bytes
-
https://huggingface.co/spaces/MBG0903/Saree-Design-App/resolve/main/utils/validation.py
- Command line
-
hf download hf://spaces/MBG0903/Saree-Design-App/utils/validation.py
-
curl -L -o validation.py https://huggingface.co/spaces/MBG0903/Saree-Design-App/resolve/main/utils/validation.py
630 Bytes
| import cv2 | |
| import numpy as np | |
| def count_regions(binary): | |
| num_labels, labels = cv2.connectedComponents( | |
| binary | |
| ) | |
| return num_labels - 1 | |
| def count_unfilled_pixels(img): | |
| white_pixels = np.sum( | |
| np.all(img == [255, 255, 255], axis=2) | |
| ) | |
| return int(white_pixels) | |
| def quality_report(binary, filled): | |
| regions = count_regions(binary) | |
| unfilled = count_unfilled_pixels( | |
| filled | |
| ) | |
| score = max( | |
| 0, | |
| 100 - (unfilled / 1000) | |
| ) | |
| return { | |
| "regions": regions, | |
| "unfilled_pixels": unfilled, | |
| "quality_score": round(score, 2) | |
| } |