MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / preprocess_image

Function preprocess_image

src/diffusers/utils/testing_utils.py:400–407  ·  view source on GitHub ↗
(image: PIL.Image, batch_size: int)

Source from the content-addressed store, hash-verified

398
399
400def preprocess_image(image: PIL.Image, batch_size: int):
401 w, h = image.size
402 w, h = (x - x % 8 for x in (w, h)) # resize to integer multiple of 8
403 image = image.resize((w, h), resample=PIL.Image.LANCZOS)
404 image = np.array(image).astype(np.float32) / 255.0
405 image = np.vstack([image[None].transpose(0, 3, 1, 2)] * batch_size)
406 image = torch.from_numpy(image)
407 return 2.0 * image - 1.0
408
409
410def export_to_gif(image: List[PIL.Image.Image], output_gif_path: str = None) -> str:

Callers

nothing calls this directly

Calls 2

transposeMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected