Tuesday, April 01, 2008

trail.py - my script to average frames in a nice way

Here is a bit of code I use to save a LOT of time in Paint Shop Pro. You run this python script with a single parameter - a file mask... (for me it's usually _*.tif)

This program will then take all the files in the current folder that match the mask, and average them, saving intermediate steps as trailnn.jpg and the final file as merge.jpg

import os, sys
import fnmatch
import Image

mask = sys.argv[1]
count = 0

# Program to average a set of photos, producing merge.jpg as a result
#
# version 0.01
# Michael Warot
#

print mask
for file in os.listdir('.'):
if fnmatch.fnmatch(file, mask):
print file
count = count + 1
in2 = Image.open(file)
if count == 1:
in1 = in2
in1 = Image.blend(in1,in2,(1.0/count))
in1.save("trail"+str(count)+".jpg","JPEG")
in1.save("merge.jpg","JPEG")

3 comments:

Nick said...

Hi Mike, I came across your script but am having issues running it. I'm new to Python and running scripts. Would you mind sharing an example of how you run the script?

Many thanks,
Nick

Mike Warot said...

Usually I have a stack of TIF files to average, and the batch file I use to do this calls the python script... it's called xyzzy.cmd, and this is the text of it..

c:\trail.py _*.tif

This assumes that python is called correctly when the .py program is run (I'm in a Windows environment)

Nick said...

Mike, thanks for your reply. I've tried both on my Mac laptop and PC at work, both return the same message: NameError: name 'in1' is not defined