Reputation: 83
i want to import a folder containing images from my local computer with python. How can i do that with python libraries.
Note: I want to import multiple images from a folder not only one image.
I want to Apply Machine Learning on that images .
Please help Me i am trying since 1 month but not find solution. I will be very Thankful to you.
Thanks in advance
I have tried Pillow library but its import only one image. And i want to import a folder full of images i.e 5k - 10k images from my local computer.
from PIL import Image
import glob
image_list = []
for filename in glob.glob('/home/zain/Downloads/natural-image/natural_images/person*'):
im=Image.open(f)
image_list.append(im)
i don't know how to import a folder of images. Please Help me. Thank in advance
Upvotes: 0
Views: 619
Reputation: 95
A simple way to load images is using either a for
loop or a simple Python list-comprehension
import os
from PIL import Image
input_dir = "/home/zain/Downloads/natural-image/natural_images/"
# load images one after another - useful for images one by one
for image in os.listdir(input_dir):
img = Image.open(os.path.join(input_dir, image))
# do whatever you like to do with the img
# load all images data at in to list
image_list = [Image.open(os.path.join(input_dir, image)) for image in os.listdir(input_dir)]
Upvotes: 1