vyvuyubhji
Browse files- main.py +2 -0
- utils/helpers.py +1 -4
main.py
CHANGED
|
@@ -51,9 +51,11 @@ async def predict_image(file: UploadFile = File(...)):
|
|
| 51 |
print(len(results))
|
| 52 |
|
| 53 |
background_element = next((element for element in results if element['label'] == 'background'), None)
|
|
|
|
| 54 |
|
| 55 |
if background_element:
|
| 56 |
background_area = calculate_mask_area(background_element['mask'], True)
|
|
|
|
| 57 |
else:
|
| 58 |
background_area = 0
|
| 59 |
|
|
|
|
| 51 |
print(len(results))
|
| 52 |
|
| 53 |
background_element = next((element for element in results if element['label'] == 'background'), None)
|
| 54 |
+
print(background_element["mask"].size)
|
| 55 |
|
| 56 |
if background_element:
|
| 57 |
background_area = calculate_mask_area(background_element['mask'], True)
|
| 58 |
+
print(background_area)
|
| 59 |
else:
|
| 60 |
background_area = 0
|
| 61 |
|
utils/helpers.py
CHANGED
|
@@ -11,8 +11,5 @@ def image_to_base64(image: Image.Image) -> str:
|
|
| 11 |
|
| 12 |
def calculate_mask_area(mask: Image.Image, background=False) -> int:
|
| 13 |
mask_array = np.array(mask)
|
| 14 |
-
|
| 15 |
-
non_zero_pixels = np.count_nonzero(mask_array == 0)
|
| 16 |
-
else:
|
| 17 |
-
non_zero_pixels = np.count_nonzero(mask_array)
|
| 18 |
return non_zero_pixels
|
|
|
|
| 11 |
|
| 12 |
def calculate_mask_area(mask: Image.Image, background=False) -> int:
|
| 13 |
mask_array = np.array(mask)
|
| 14 |
+
non_zero_pixels = np.count_nonzero(mask_array)
|
|
|
|
|
|
|
|
|
|
| 15 |
return non_zero_pixels
|