Read image from path using ``PIL.Image``. Args: path (str): path to an image. Returns: PIL image
(path)
| 28 | |
| 29 | |
| 30 | def read_image(path): |
| 31 | """Read image from path using ``PIL.Image``. |
| 32 | |
| 33 | Args: |
| 34 | path (str): path to an image. |
| 35 | |
| 36 | Returns: |
| 37 | PIL image |
| 38 | """ |
| 39 | if not osp.exists(path): |
| 40 | raise IOError('No file exists at {}'.format(path)) |
| 41 | |
| 42 | while True: |
| 43 | try: |
| 44 | img = Image.open(path).convert('RGB') |
| 45 | return img |
| 46 | except IOError: |
| 47 | print( |
| 48 | 'Cannot read image from {}, ' |
| 49 | 'probably due to heavy IO. Will re-try'.format(path) |
| 50 | ) |
| 51 | |
| 52 | |
| 53 | def listdir_nohidden(path, sort=False): |