1

I have a folder containing 10K tiff files, how can i import all the files using python so that i can do some predictive modelling.

thanks NK

1
  • 1
    maybe start with writing some code and sharing what you did? Commented Oct 16, 2017 at 12:50

1 Answer 1

3

Use the following approach:

import os 
from PIL import Image
import numpy as np

dirname = 'tiff_folder_path'
final = []
for fname in os.listdir(dirname):
    im = Image.open(os.path.join(dirname, fname))
    imarray = np.array(im)
    final.append(imarray)

final = np.asarray(final) # shape = (60000,28,28)
Sign up to request clarification or add additional context in comments.

2 Comments

how do i stack/append the arrays for each file to make it a (60000,28,28) as i have 60K files of 28*28 pic. I tried the following line: final = np.stack((final,imarray), axis = 0) and getting error "all input arrays must have the same shape"
@user6658936 I have updated my answer as per your requirements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.