pythonnumpypython-imaging-libraryimage-augmentationalbumentations

Albumentations - Read images after augmentation


I would like to know how to read (if it is possible) an image after augmentation by Albumentations.
I tried:

my_img = 'xyz.jpg'

image = cv2.imread(my_img)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
transformed = transform(image=image)
new_img = np.array(list(transformed.values())
Image.formarray(new_img)

but I get this error:

TypeError: Cannot handle this data type: (1, 1, 512, 3), |u1

Solution

  • The variable transformed is a dictionary type. You have to display the value stored in the key image as an image array.

    >>> type(transformed)
    <class 'dict'>
    
    # store the value in image key as an array & display it
    transformed_image = transformed['image']
    cv2.imshow(transformed_image)