'Code for changing multiple .img files into .png, then into numpy array
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!
Solution 1:[1]
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'))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
