Why can Ipython.display.Image not read my png files? Is there an alternative?

  image, image-processing, ipython, python

I have written the following code in Google Colab:

import os
import cv2
from IPython.display import Image
import random

folder_train_val = '/content/drive/MyDrive/Colab Notebooks/data/kd_pictures'

files = os.listdir(folder_train_val)

twenty_images = random.sample(files, 20)

for file in twenty_images:
    display(Image(filename=os.path.join(folder_train_val,file)))

The images have the following properties:

for file in twenty_images[:1]:
  im = cv2.imread(os.path.join(folder_train_val,file))
  print(type(im))
  print(im.shape)
  print(type(im.shape))
  print(file)

<class 'numpy.ndarray'>
(500, 500, 3)
<class 'tuple'>
VGKDLMBJGBXTGI-SJCJKPOMSA-N

I get the following error

ValueError: Cannot embed the '/content/drive/mydrive/colab notebooks/data/kd_pictures/dwrxfeitvbnrmk-jxoaffinsa-n' image format

The Ipython docs say that png is an accepted format type. So why cannot my images not be embedded?

Source: Python Questions

LEAVE A COMMENT