r""" Convert a PIL image or a list of PIL images to NumPy arrays. Args: images (`PIL.Image.Image` or `list[PIL.Image.Image]`): The PIL image or list of images to convert to NumPy format. Returns: `np.ndarray`: A NumPy
(images: list[PIL.Image.Image] | PIL.Image.Image)
| 150 | |
| 151 | @staticmethod |
| 152 | def pil_to_numpy(images: list[PIL.Image.Image] | PIL.Image.Image) -> np.ndarray: |
| 153 | r""" |
| 154 | Convert a PIL image or a list of PIL images to NumPy arrays. |
| 155 | |
| 156 | Args: |
| 157 | images (`PIL.Image.Image` or `list[PIL.Image.Image]`): |
| 158 | The PIL image or list of images to convert to NumPy format. |
| 159 | |
| 160 | Returns: |
| 161 | `np.ndarray`: |
| 162 | A NumPy array representation of the images. |
| 163 | """ |
| 164 | if not isinstance(images, list): |
| 165 | images = [images] |
| 166 | images = [np.array(image).astype(np.float32) / 255.0 for image in images] |
| 167 | images = np.stack(images, axis=0) |
| 168 | |
| 169 | return images |
| 170 | |
| 171 | @staticmethod |
| 172 | def numpy_to_pt(images: np.ndarray) -> torch.Tensor: |
no outgoing calls