问题
I am reading images on the disk, how to make a for
and where to put it to plot the first 50 images on the screen, I want to make sure, that I'm reading the right images, it's for deep learning.
def load_clef_database():
img_data_list = []
dataset_dir = "/Users/PlantCLEF2015"
root = os.path.join(dataset_dir, 'train')
filenames = [] # files
class_species = []
class_species_unique = []
class_species_unique_id = []
class_familys = []
class_geni = []
class_ids = []
class_contents = []
metadata = [] # xml dat
leafscans = []
leafscansfiles = []
for file in os.listdir(root):
path = os.path.join(root, file)
if file.endswith('.xml'):
metadata.append(path)
elif file.endswith('.jpg'):
filenames.append(path)
filenames = sorted(filenames)
metadata = sorted(metadata)
# assert len(filenames) == len(metadata)
for i in range(len(metadata)):
class_data = etree.parse(metadata[i])
class_family = class_data.findtext('Family')
class_genus = class_data.findtext('Genus')
class_spec = class_data.findtext('Species')
class_id = class_data.findtext('ClassId')
class_content = class_data.findtext('Content')
if class_content == 'Flower':
# print(class_content)
leafscans.append(metadata[i])
leafscansfiles.append(filenames[i])
if class_spec not in class_species_unique:
class_species_unique.append(class_spec)
class_geni.append(class_genus)
class_familys.append(class_family)
class_ids.append(class_id)
if class_id not in class_species_unique_id:
class_species_unique_id.append(class_id)
class_contents.append(class_content)
print(len(leafscansfiles))'''
回答1:
One quick way of plotting the images is using skimage's montage function
import matplotlib.pyplot as plt
import numpy as np
from skimage.util import montage
#creating a random image
images = np.zeros((50, 150, 150, 3), np.uint8)
for i in range(images.shape[0]):
images[i]=np.random.randint(0, 255, 3)
print("image size before montage", images.shape)
image size before montage (50, 150, 150, 3)
out = montage(images, multichannel=True)
print("image size after montage", out.shape)
image size after montage (1200, 1200, 3)
plt.figure(figsize=(10,10))
plt.imshow(out)
plt.show()
来源:https://stackoverflow.com/questions/65032456/im-reading-images-on-the-disk-how-to-plot-like-the-first-50-images