Code for changing multiple .img files into .png, then into numpy array

58 views Asked by At

I'm doing a convolutional neural network classification and currently all my tiles are in .img format (thanks ArcMap). I know I need to get them in .png format, but haven't found code that could convert a whole folder of them. Is that doable?

Eventually I also need to get all those .pngs into a numpy array. I found basic code that will do it for just .png, but is there a way to convert the whole folder at once?

Thanks everyone!

1

There are 1 answers

2
Kenny On

Yes it is doable, just use Python Pil! and loop over all files in the folder with glob.

Some example code:

import os
from PIL import Image
import glob

counter = 0
for image in glob.glob("/Users/Testfolder/*.jpg"):
    counter = counter + 1
    img = Image.open(image)
    img.save('/Users/Testfolder/' + (str(counter)+'img.png'))