A few lines of python code to read jpg images from a directory

Bharath Sudharsan
1 min readJun 2, 2020

--

This is a tutorial to read a .jpg image file from your local directory using PIL.Image & numpy. Then display it using Mlatplotlib.

import numpy as np
import matplotlib.pyplot as plt
import PIL.Image as Image
#grace_hopper = tf.keras.utils.get_file('image.jpg','https://storage.googleapis.com/download.tensorflow.org/example_images/grace_hopper.jpg')
#or
grace_hopper = Image.open('data/cloth_categories/test_images/test-1.jpeg')
grace_hopper = np.array(grace_hopper)/255.0
grace_hopper.shape
plt.imshow(grace_hopper)
plt.show()

--

--