2011-11-03 05:19:21 +00:00
|
|
|
#!/usr/local/bin/python
|
|
|
|
|
|
|
|
import os, sys
|
|
|
|
import Image
|
|
|
|
import time
|
2011-11-04 05:27:39 +00:00
|
|
|
import numpy as np
|
|
|
|
import scipy as sp
|
|
|
|
|
|
|
|
from scipy import misc
|
|
|
|
|
2011-11-03 05:19:21 +00:00
|
|
|
|
|
|
|
start = time.time()
|
|
|
|
|
2011-11-03 14:50:09 +00:00
|
|
|
#maxsize = 3000, 3000
|
2011-11-03 05:19:21 +00:00
|
|
|
|
|
|
|
dir = sys.argv[1]
|
|
|
|
|
|
|
|
list = os.listdir(dir)
|
2011-11-04 05:27:39 +00:00
|
|
|
first = 0
|
|
|
|
count = 0
|
|
|
|
|
|
|
|
# for file in list:
|
|
|
|
# try:
|
|
|
|
# im = misc.imread(dir + file)
|
|
|
|
# except IOError:
|
|
|
|
# continue
|
|
|
|
#
|
|
|
|
# count +=1
|
|
|
|
# print 'Processing image ' + str(count)
|
|
|
|
#
|
|
|
|
# if first == 0:
|
|
|
|
# new = im
|
|
|
|
# first = 1
|
|
|
|
# continue
|
|
|
|
#
|
|
|
|
# from numpy import *
|
|
|
|
#
|
|
|
|
# for nrow, row in np.nditer([new,im], op_flags=['readwrite']):
|
|
|
|
# for npixel, pixel in np.nditer([nrow,row], op_flags=['readwrite']):
|
|
|
|
# npixel = maximum(npixel, pixel)
|
|
|
|
#
|
|
|
|
# misc.imsave('stack_' + str(int(time.time())) + '.jpg', new)
|
2011-11-03 05:19:21 +00:00
|
|
|
|
|
|
|
images = []
|
|
|
|
|
|
|
|
for file in list:
|
|
|
|
try:
|
|
|
|
im = Image.open(dir + file)
|
|
|
|
except IOError:
|
|
|
|
continue
|
2011-11-03 14:50:09 +00:00
|
|
|
print 'Getting image...'
|
2011-11-03 05:19:21 +00:00
|
|
|
|
|
|
|
if 'maxsize' in globals():
|
|
|
|
im.thumbnail(maxsize, Image.ANTIALIAS)
|
|
|
|
|
|
|
|
images.append(im)
|
|
|
|
|
|
|
|
count = len(images)
|
|
|
|
(w, h) = images[0].size
|
|
|
|
new = Image.new('RGB', (w, h))
|
|
|
|
i = 1
|
2011-11-04 05:27:39 +00:00
|
|
|
pixels = np.zeros((w,h,3), dtype=np.uint8)
|
2011-11-03 05:19:21 +00:00
|
|
|
|
|
|
|
for im in images:
|
|
|
|
print "Image " + str(i) + " of " + str(count)
|
|
|
|
(w, h) = im.size
|
|
|
|
for x in range(w):
|
|
|
|
for y in range(h):
|
|
|
|
raw = im.getpixel((x,y))
|
|
|
|
if raw[0] > pixels[x][y][0]:
|
|
|
|
pixels[x][y][0] = raw[0]
|
|
|
|
if raw[1] > pixels[x][y][1]:
|
|
|
|
pixels[x][y][1] = raw[1]
|
|
|
|
if raw[2] > pixels[x][y][2]:
|
|
|
|
pixels[x][y][2] = raw[2]
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
|
|
|
|
for x in range(w):
|
|
|
|
for y in range(h):
|
|
|
|
new.putpixel((x,y), (pixels[x][y][0], pixels[x][y][1], pixels[x][y][2]))
|
2011-11-04 05:27:39 +00:00
|
|
|
|
|
|
|
new.save('stack_' + str(time.time()) + '.jpg', 'JPEG')
|
2011-11-03 05:19:21 +00:00
|
|
|
|
2011-11-03 14:50:09 +00:00
|
|
|
print str(count) + ' images processed in ' + str(int(time.time() - start)) + ' seconds.'
|