Spaces:
Runtime error
Runtime error
Update SegCloth.py
Browse files- SegCloth.py +15 -15
SegCloth.py
CHANGED
|
@@ -52,21 +52,21 @@ def segment_clothing(img, clothes=["Hat", "Upper-clothes", "Skirt", "Pants", "Dr
|
|
| 52 |
# Application du masque sur l'image vide
|
| 53 |
empty_image.paste(segmented_part, mask=mask_image)
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
# Encodage de l'image recadrée en base64
|
| 71 |
imageBase64 = encode_image_to_base64(cropped_image)
|
| 72 |
result_images.append(imageBase64)
|
|
|
|
| 52 |
# Application du masque sur l'image vide
|
| 53 |
empty_image.paste(segmented_part, mask=mask_image)
|
| 54 |
|
| 55 |
+
# Vérifier si l'image est significative avant le recadrage
|
| 56 |
+
if is_image_significant(empty_image):
|
| 57 |
+
# Déterminer la bounding box du masque
|
| 58 |
+
bbox = mask_image.getbbox()
|
| 59 |
+
if bbox:
|
| 60 |
+
# Ajouter la marge autour de la bounding box
|
| 61 |
+
left, top, right, bottom = bbox
|
| 62 |
+
left = max(0, left - margin)
|
| 63 |
+
top = max(0, top - margin)
|
| 64 |
+
right = min(img.width, right + margin)
|
| 65 |
+
bottom = min(img.height, bottom + margin)
|
| 66 |
+
|
| 67 |
+
# Recadrer l'image à la taille du masque avec la marge
|
| 68 |
+
cropped_image = empty_image.crop((left, top, right, bottom))
|
| 69 |
+
|
| 70 |
# Encodage de l'image recadrée en base64
|
| 71 |
imageBase64 = encode_image_to_base64(cropped_image)
|
| 72 |
result_images.append(imageBase64)
|