1

How can I give a specific name to every saved image?

This is the code that I have now

for i in img_list:
    im = PImage.fromarray(i) 
    im.save(dir + '/' + 'img' + str(i) +'.tiff', 'tiff')

The problem is that when they are saved the name of the images is img and the respective numpy array.

I would like to have an output like img_1.tiff

img_2.tiff

and so on

Aran
  • 45
  • 5

1 Answers1

1

Use enumerate:

for idx, i in enumerate(img_list):
    im = PImage.fromarray(i) 
    im.save("{0}/img{1}{2}.tiff".format(dir,str(i),idx))
blackbrandt
  • 2,010
  • 1
  • 15
  • 32