Spaces:
Running
Running
| 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) | |
| } |