Spaces:
Paused
Paused
File size: 630 Bytes
2e47f12 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 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)
} |