Skip to content Skip to sidebar Skip to footer

Use Original File Name To Save Image

I want to save image with original file name for example if original file name is hero so the processed image name should be hero_Zero.png. I dont know how to pass file name in d

Solution 1:

Add an extra argument to your function definition. Instead of just taking the directory and image, also pass the filename. The result will look like this:

def run(dirs, img, f_name):
  for (x, y) in labels:
        component = uf.find(labels[(x, y)])
        labels[(x, y)] = component   
        if labels[(x, y)]==0:
            Zero[y][x]=int(255)
            count=count+1
            if count<=43:
                continue
            elif count>43:
                Zeroth = Image.fromarray(Zero)
                Zeroth.save(os.path.join(dirs, f_name + '_Zero.png'), 'png')

Post a Comment for "Use Original File Name To Save Image"