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

Function load_image

src/diffusers/utils/testing_utils.py:369–397  ·  view source on GitHub ↗

Loads `image` to a PIL Image. Args: image (`str` or `PIL.Image.Image`): The image to convert to the PIL Image format. Returns: `PIL.Image.Image`: A PIL Image.

(image: Union[str, PIL.Image.Image])

Source from the content-addressed store, hash-verified

367
368
369def load_image(image: Union[str, PIL.Image.Image]) -> PIL.Image.Image:
370 """
371 Loads `image` to a PIL Image.
372
373 Args:
374 image (`str` or `PIL.Image.Image`):
375 The image to convert to the PIL Image format.
376 Returns:
377 `PIL.Image.Image`:
378 A PIL Image.
379 """
380 if isinstance(image, str):
381 if image.startswith("http://") or image.startswith("https://"):
382 image = PIL.Image.open(requests.get(image, stream=True).raw)
383 elif os.path.isfile(image):
384 image = PIL.Image.open(image)
385 else:
386 raise ValueError(
387 f"Incorrect path or url, URLs must start with `http://` or `https://`, and {image} is not a valid path"
388 )
389 elif isinstance(image, PIL.Image.Image):
390 image = image
391 else:
392 raise ValueError(
393 "Incorrect format used for image. Should be an url linking to an image, a local path, or a PIL image."
394 )
395 image = PIL.ImageOps.exif_transpose(image)
396 image = image.convert("RGB")
397 return image
398
399
400def preprocess_image(image: PIL.Image, batch_size: int):

Calls

no outgoing calls

Tested by

no test coverage detected