(path, size=(1024, 1024), color_type=['rgb', 'gray'][0])
| 9 | |
| 10 | |
| 11 | def path_to_image(path, size=(1024, 1024), color_type=['rgb', 'gray'][0]): |
| 12 | if color_type.lower() == 'rgb': |
| 13 | image = cv2.imread(path) |
| 14 | elif color_type.lower() == 'gray': |
| 15 | image = cv2.imread(path, cv2.IMREAD_GRAYSCALE) |
| 16 | else: |
| 17 | print('Select the color_type to return, either to RGB or gray image.') |
| 18 | return |
| 19 | if size: |
| 20 | image = cv2.resize(image, size, interpolation=cv2.INTER_LINEAR) |
| 21 | if color_type.lower() == 'rgb': |
| 22 | image = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)).convert('RGB') |
| 23 | else: |
| 24 | image = Image.fromarray(image).convert('L') |
| 25 | return image |
| 26 | |
| 27 | |
| 28 |
no test coverage detected