How to output picture out of a loop

Hello all, I am having a little trouble with a python code. It seems to be a simple fix but I am not experienced enough using python so solve it. So I am trying to take a set of images and run a code, only problem is that I have a loop that runs successfully but will not output any image. I know I need to output the image in a separate folder and change the name but not sure how.

Here is an example of the picture set

And a link to the script:

As far as I understand you’re trying to save the results into a new file and not just plot them. One easy strategy would be to generate a string value where the original file name is changed into the new file name. You could easily do this by a built-in method:
filename.replace(’.png’, ‘_result.png’)

Then save the image with this new name. Does this make sense?