Read image data from specified file or files, it can read a list of images and stack them together as multi-channel data in `get_data()`. Note that the returned object is PIL image or list of PIL image. Args: data: file name or a list of file names to re
(self, data: Sequence[PathLike] | PathLike | np.ndarray, **kwargs)
| 1373 | return has_pil and is_supported_format(filename, suffixes) |
| 1374 | |
| 1375 | def read(self, data: Sequence[PathLike] | PathLike | np.ndarray, **kwargs): |
| 1376 | """ |
| 1377 | Read image data from specified file or files, it can read a list of images |
| 1378 | and stack them together as multi-channel data in `get_data()`. |
| 1379 | Note that the returned object is PIL image or list of PIL image. |
| 1380 | |
| 1381 | Args: |
| 1382 | data: file name or a list of file names to read. |
| 1383 | kwargs: additional args for `Image.open` API in `read()`, will override `self.kwargs` for existing keys. |
| 1384 | Mode details about available args: |
| 1385 | https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.open |
| 1386 | |
| 1387 | """ |
| 1388 | img_: list[PILImage.Image] = [] |
| 1389 | |
| 1390 | filenames: Sequence[PathLike] = ensure_tuple(data) |
| 1391 | kwargs_ = self.kwargs.copy() |
| 1392 | kwargs_.update(kwargs) |
| 1393 | for name in filenames: |
| 1394 | img = PILImage.open(name, **kwargs_) |
| 1395 | if callable(self.converter): |
| 1396 | img = self.converter(img) |
| 1397 | img_.append(img) |
| 1398 | |
| 1399 | return img_ if len(filenames) > 1 else img_[0] |
| 1400 | |
| 1401 | def get_data(self, img) -> tuple[np.ndarray, dict]: |
| 1402 | """ |