aboutsummaryrefslogtreecommitdiff
path: root/fly-tools/derivebackground.py
blob: 1679ae0ef132af50b57804b955249beb2a028e69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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