Quellcode durchsuchen

update align_and_crop and letterbox_resize_image about border_value

quarrying vor 4 Jahren
Ursprung
Commit
0ca17d95e5
2 geänderte Dateien mit 5 neuen und 4 gelöschten Zeilen
  1. 3 2
      khandy/image/align_and_crop.py
  2. 2 2
      khandy/image/resize.py

+ 3 - 2
khandy/image/align_and_crop.py

@@ -38,14 +38,15 @@ def get_similarity_transform(src_pts, dst_pts):
     
     
 def align_and_crop(image, landmarks, std_landmarks, align_size, 
-                   return_transform_matrix=False):
+                   border_value=0, return_transform_matrix=False):
     landmarks = np.asarray(landmarks)
     std_landmarks = np.asarray(std_landmarks)
     xform_matrix = get_similarity_transform(landmarks, std_landmarks)
 
     landmarks_ex = np.pad(landmarks, ((0,0),(0,1)), mode='constant', constant_values=1)
     dst_landmarks = np.dot(landmarks_ex, xform_matrix[:2,:].T)
-    dst_image = cv2.warpAffine(image, xform_matrix[:2,:], dsize=align_size)
+    dst_image = cv2.warpAffine(image, xform_matrix[:2,:], dsize=align_size, 
+                               borderValue=border_value)
     if return_transform_matrix:
         return dst_image, dst_landmarks, xform_matrix
     else:

+ 2 - 2
khandy/image/resize.py

@@ -94,7 +94,7 @@ def resize_image_long(image, dst_size, return_scale=False, interpolation='biline
         return resized_image, scale
         
         
-def letterbox_resize_image(image, dst_width, dst_height, pad_val=0,
+def letterbox_resize_image(image, dst_width, dst_height, border_value=0,
                            return_scale=False, interpolation='bilinear'):
     """Resize an image preserving the original aspect ratio using padding.
     
@@ -111,7 +111,7 @@ def letterbox_resize_image(image, dst_width, dst_height, pad_val=0,
     padded_shape = list(resized_image.shape)
     padded_shape[0] = dst_height
     padded_shape[1] = dst_width
-    padded_image = np.full(padded_shape, pad_val, image.dtype)
+    padded_image = np.full(padded_shape, border_value, image.dtype)
 
     dw = (dst_width - resize_w) // 2
     dh = (dst_height - resize_h) // 2