(f, use_pyspng: bool=False)
| 455 | #---------------------------------------------------------------------------- |
| 456 | |
| 457 | def load_image_from_buffer(f, use_pyspng: bool=False) -> np.ndarray: |
| 458 | if use_pyspng: |
| 459 | image = pyspng.load(f.read()) |
| 460 | else: |
| 461 | image = np.array(PIL.Image.open(f)) |
| 462 | if image.ndim == 2: |
| 463 | image = image[:, :, np.newaxis] # HW => HWC |
| 464 | image = image.transpose(2, 0, 1) # HWC => CHW |
| 465 | |
| 466 | return image |
| 467 | |
| 468 | #---------------------------------------------------------------------------- |
| 469 |
no test coverage detected