From c80efaa3a6837ecb7360cb5c3b73728de98c0a14 Mon Sep 17 00:00:00 2001 From: mutantturkey Date: Mon, 2 Jul 2012 11:37:31 -0400 Subject: added an median based background deriver --- fly-tools/derivebackground.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 fly-tools/derivebackground.py (limited to 'fly-tools/derivebackground.py') diff --git a/fly-tools/derivebackground.py b/fly-tools/derivebackground.py new file mode 100755 index 0000000..1679ae0 --- /dev/null +++ b/fly-tools/derivebackground.py @@ -0,0 +1,31 @@ +import numpy +import sys +import Image +import scipy +from scipy import stats +if len(sys.argv) != 3: + print "usage:", sys.argv[0], " filelist-path output-path" + +filelistpath = sys.argv[1] +outputpath = sys.argv[2] + +filelist = numpy.loadtxt(filelistpath, dtype=numpy.str) +nimages = len(filelist) + +temp = numpy.asarray(Image.open(filelist[0])) +height = temp.shape[0] +width = temp.shape[1] + +mov = numpy.empty((nimages, height, width, 3), dtype=numpy.uint8) + +for i in xrange(nimages): + mov[i] = numpy.asarray(Image.open(filelist[i])) + +bg = scipy.stats.mode(mov, axis=0) + +#image.fromarray(numpy.uint8(bg)).save(outputpath) +scipy.misc.imsave(outputpath, bg) + +print bg +print "created", outputpath + -- cgit v1.2.3