I want to load same images from directory and reshape them using reshape function using python.
How can i do this?
Assuming that you have scipy installed and assuming that with "reshape" you actually mean "resize", the following code should load all images from the directory /foo/bar, resize them to 64x64 and add them to the list images:
import os
from scipy import ndimage, misc
images = []
for root, dirnames, filenames in os.walk("/foo/bar"):
for filename in filenames:
if re.search("\.(jpg|jpeg|png|bmp|tiff)$", filename):
filepath = os.path.join(root, filename)
image = ndimage.imread(filepath, mode="RGB")
image_resized = misc.imresize(image, (64, 64))
images.append(image_resized)
If you need a numpy array (to call reshape) then just add images = np.array(images) at the end (with import numpy as np at the start).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With