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

Method numpy_to_depth

src/diffusers/image_processor.py:714–732  ·  view source on GitHub ↗

Convert a NumPy depth image or a batch of images to a PIL image.

(self, images: np.ndarray)

Source from the content-addressed store, hash-verified

712 return image[:, :, 1] * 2**8 + image[:, :, 2]
713
714 def numpy_to_depth(self, images: np.ndarray) -> List[PIL.Image.Image]:
715 """
716 Convert a NumPy depth image or a batch of images to a PIL image.
717 """
718 if images.ndim == 3:
719 images = images[None, ...]
720 images_depth = images[:, :, :, 3:]
721 if images.shape[-1] == 6:
722 images_depth = (images_depth * 255).round().astype("uint8")
723 pil_images = [
724 Image.fromarray(self.rgblike_to_depthmap(image_depth), mode="I;16") for image_depth in images_depth
725 ]
726 elif images.shape[-1] == 4:
727 images_depth = (images_depth * 65535.0).astype(np.uint16)
728 pil_images = [Image.fromarray(image_depth, mode="I;16") for image_depth in images_depth]
729 else:
730 raise Exception("Not supported")
731
732 return pil_images
733
734 def postprocess(
735 self,

Callers 1

postprocessMethod · 0.95

Calls 1

rgblike_to_depthmapMethod · 0.95

Tested by

no test coverage detected