Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can subplot images from each folder?

I’m listing images with these code:

for folder in folder_list:
    img = os.path.join(f"{train_dir}/{folder}/00001.png")
    print(img)

output is:

Fish/train/Black Sea Sprat/00001.png /Fish/train/Gilt-Head
Bream/00001.png Fish/train/Hourse Mackerel/00001.png Fish/train/Red
Mullet/00001.png /Fish/train/Red Sea Bream/00001.png Fish/train/Sea
Bass/00001.png Fish/train/Shrimp/00001.png /Fish/train/Striped Red
Mullet/00001.png Downloads/Fish/train/Trout/00001.
there is 9 pictures.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are just printing image file names. You need to enumerate the list of images and plot one by one using plt.sublot

import os
import matplotlib.pyplot as plt
import PIL
files=[] #empty list
rows = 3 #Number of rows u need

for folder in folder_list:
    img = os.path.join(f"{train_dir}/{folder}/00001.png")
    files.append(img)
   
for num, x in enumerate(files):
    img = PIL.Image.open(x)
    plt.subplot(rows,6,num+1)
    plt.title(x.split('.')[0])
    plt.axis('off')
    plt.imshow(img)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading