How to load and visualize multiple images in Python

PHOTO EMBED

Sat Sep 17 2022 19:00:47 GMT+0000 (Coordinated Universal Time)

Saved by @DiegoEraso #python

# librerias necesarias
import glob
import cv2
import matplotlib.pyplot as plt
#Leer y mostrar una sola imagen
file = 'D:\BinaryStudy\demo\Images\image001.tif'
image = cv2.imread(file)
cv2.imshow('display', image)
cv2.waitKey(0)
cv2.destrouAllWindows() 
#Leer todas la imagenes
file = 'D:\BinaryStudy\demo\Images\*.tif' 
glob.glob(file)
# Using List Comprehension to read all images
images = [cv2.imread(image) for image in glob.glob(file)]
#mostrar las imagenes
# Define a figure of size (8, 8)
fig=plt.figure(figsize=(8, 8))
# Define row and cols in the figure
rows, cols = 2, 2
# Display first four images
for j in range(0, cols*rows):
  fig.add_subplot(rows, cols, j+1)
  plt.imshow(images[j])
plt.show()

content_copyCOPY

https://www.binarystudy.com/2020/10/different-ways-to-load-images-in-python_18.html