-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfuji-merge-frames.py
45 lines (35 loc) · 1.41 KB
/
fuji-merge-frames.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from ij import IJ, ImagePlus
from ij.process import ShortProcessor
from ij.io import FileSaver
from array import zeros
import os
import subprocess
#basename = '141006_163724'
basename = '141011_155913'
#basename = '141016_155913'
#basename = 'test/DSCF3564'
frame = []
for fn in ['0', '1']:
filename = os.environ['HOME'] + '/' + basename + '_' + fn + '.pgm'
imp = IJ.openImage(filename)
if imp is None:
print "Could not open image from file:", filename
frame.append(imp)
print 'loaded frames'
width = frame[0].width
height = frame[0].height
bpix = zeros('h', (width + height)**2)
for fn in [0, 1]:
pix = frame[fn].getProcessor().getPixels()
for i in range(len(pix)):
x = i % width + i / width + fn # the second frame (fn == 1) is shifted 1px to the right
y = (width - i % width - 1) + (i / width)
bpix[y * (width + height) + x] = pix[i]
print 'wrote frame %s' % fn
ip = ShortProcessor(width + height, width + height, bpix, None)
bayer = ImagePlus("Sensor", ip)
fs = FileSaver(bayer)
fs.saveAsTiff(os.path.dirname(filename) + '/' + 'raw.tiff')
print '/opt/local/bin/tiffset' + ' -s' + ' 270' + ' width = ' + str(width) + ', height = ' + str(height) + ' ' + os.environ['HOME'] + '/test/' + 'raw.tiff'
subprocess.call(['/opt/local/bin/tiffset', '-s', '270', 'width = ' + str(width) + ', height = ' + str(height), os.environ['HOME'] + '/test/' + 'raw.tiff'])
bayer.show()