49 50 51 def _get_energy(gray: np.ndarray) -> np.ndarray: 52 """Get backward energy map from the source image""" 53 assert gray.ndim == 2 54 55 gray = gray.astype(np.float32) 56 grad_x = sobel(gray, axis=1)
215 energy_mode: str, 216 aux_energy: Optional[np.ndarray], 217 ) -> Tuple[np.ndarray, Optional[np.ndarray]]: 218 """Reduce the width of image by delta_width pixels""" 219 assert src.ndim in (2, 3) and delta_width >= 0 220 if src.ndim == 2: 221 gray = src 222 src_h, src_w = src.shape
273 aux_energy: Optional[np.ndarray], 274 step_ratio: float, 275 ) -> Tuple[np.ndarray, Optional[np.ndarray]]: 276 """Expand the width of image by delta_width pixels""" 277 assert src.ndim in (2, 3) and delta_width >= 0 278 if not 0 < step_ratio <= 1: 279 raise ValueError(f"expect `step_ratio` to be between (0,1], got {step_ratio}") 280
299 aux_energy: Optional[np.ndarray], 300 step_ratio: float, 301 ) -> Tuple[np.ndarray, Optional[np.ndarray]]: 302 """Resize the width of image by removing vertical seams""" 303 assert src.size > 0 and src.ndim in (2, 3) 304 assert width > 0 305 306 src_w = src.shape[1]
300 step_ratio: float, 301 ) -> Tuple[np.ndarray, Optional[np.ndarray]]: 302 """Resize the width of image by removing vertical seams""" 303 assert src.size > 0 and src.ndim in (2, 3) 304 assert width > 0 305 306 src_w = src.shape[1] 307 if src_w < width:
329 aux_energy: Optional[np.ndarray], 330 step_ratio: float, 331 ) -> Tuple[np.ndarray, Optional[np.ndarray]]: 332 """Resize the height of image by removing horizontal seams""" 333 assert src.ndim in (2, 3) and height > 0 334 if aux_energy is not None: 335 aux_energy = aux_energy.T 336 src = _transpose_image(src)
431 class MaskPreview(SaveImage): 432 def __init__(self): 433 self.output_dir = folder_paths.get_temp_directory() 434 self.type = "temp" 435 self.prefix_append = "_temp_" + ''.join(random.choice("abcdefghijklmnopqrstupvxyz") for x in range(5)) 436 self.compress_level = 4 437 438 @classmethod