0

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
    Have you looked at pillow? Pillow allows conversion among picture formats and conversion to numpy arrays. https://pillow.readthedocs.io/en/stable/reference/Image.html – jfish003 Apr 20 '22 at 13:40

1 Answers1

0

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'))
Kenny
  • 88
  • 3
  • 14
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 20 '22 at 15:29
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 21 '22 at 00:42