update garment pil
Browse files
app.py
CHANGED
|
@@ -102,15 +102,31 @@ def apply_parsing_white_mask_to_person_cv2(
|
|
| 102 |
person_pil: Image.Image,
|
| 103 |
parsing_img: Image.Image
|
| 104 |
) -> np.ndarray:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
person_rgb = np.array(person_pil.convert("RGB"), dtype=np.uint8)
|
|
|
|
|
|
|
| 106 |
mask = np.array(parsing_img.convert("L"), dtype=np.uint8)
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
result_rgb = np.full_like(person_rgb, 255, dtype=np.uint8)
|
| 109 |
result_rgb[white_mask] = person_rgb[white_mask]
|
|
|
|
| 110 |
result_bgr = cv2.cvtColor(result_rgb, cv2.COLOR_RGB2BGR)
|
| 111 |
return result_bgr
|
| 112 |
|
| 113 |
|
|
|
|
| 114 |
def compute_hw_from_person(person_path: str):
|
| 115 |
img = _imread_or_raise(person_path)
|
| 116 |
orig_h, orig_w = img.shape[:2]
|
|
|
|
| 102 |
person_pil: Image.Image,
|
| 103 |
parsing_img: Image.Image
|
| 104 |
) -> np.ndarray:
|
| 105 |
+
"""
|
| 106 |
+
person_pil(RGB) 크기에 parsing_img(L) 마스크를 맞춰서
|
| 107 |
+
흰색(255) 영역만 person을 남기고 나머지는 흰색 배경으로 만드는 함수.
|
| 108 |
+
|
| 109 |
+
- parsing_img는 person 크기에 반드시 맞춰야 함 (NEAREST)
|
| 110 |
+
"""
|
| 111 |
person_rgb = np.array(person_pil.convert("RGB"), dtype=np.uint8)
|
| 112 |
+
|
| 113 |
+
# parsing 마스크 (L)
|
| 114 |
mask = np.array(parsing_img.convert("L"), dtype=np.uint8)
|
| 115 |
+
|
| 116 |
+
# ✅ 핵심: 크기 불일치 해결 (H,W) 맞춤
|
| 117 |
+
if mask.shape[0] != person_rgb.shape[0] or mask.shape[1] != person_rgb.shape[1]:
|
| 118 |
+
mask = cv2.resize(mask, (person_rgb.shape[1], person_rgb.shape[0]), interpolation=cv2.INTER_NEAREST)
|
| 119 |
+
|
| 120 |
+
white_mask = (mask == 255)
|
| 121 |
+
|
| 122 |
result_rgb = np.full_like(person_rgb, 255, dtype=np.uint8)
|
| 123 |
result_rgb[white_mask] = person_rgb[white_mask]
|
| 124 |
+
|
| 125 |
result_bgr = cv2.cvtColor(result_rgb, cv2.COLOR_RGB2BGR)
|
| 126 |
return result_bgr
|
| 127 |
|
| 128 |
|
| 129 |
+
|
| 130 |
def compute_hw_from_person(person_path: str):
|
| 131 |
img = _imread_or_raise(person_path)
|
| 132 |
orig_h, orig_w = img.shape[:2]
|