-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsercat.py
More file actions
executable file
·72 lines (63 loc) · 2.54 KB
/
sercat.py
File metadata and controls
executable file
·72 lines (63 loc) · 2.54 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), "astrolove"))
sys.path.append("/usr/lib/astrolove")
import numpy as np
import astrolib as AL
from optparse import OptionParser
parser = OptionParser(usage = "usage: %prog [opts] " + AL.expand_file_list_help)
parser.add_option("--out", type = "string", default = "out.ser",
help = "output file template, default out.ser")
parser.add_option("--crop-x", type = "int", default = 0, help = "crop x")
parser.add_option("--crop-y", type = "int", default = 0, help = "crop y")
parser.add_option("--crop-w", type = "int", default = -1, help = "crop w")
parser.add_option("--crop-h", type = "int", default = -1, help = "crop h")
parser.add_option("--mode", type = "int", default = 3, help = "debayer mode")
parser.add_option("--raw", action="store_true", dest="is_raw")
parser.add_option("--register", action="store_true", dest="is_register")
parser.add_option("--limit", type = "int", default = -1, help = "number of frames to process")
(options, args) = parser.parse_args()
crop_x = options.crop_x
crop_y = options.crop_y
crop_w = options.crop_w
crop_h = options.crop_h
out_file = options.out
limit = options.limit
ser_out = None
ref = None
def process():
global ser_out, ref, crop_x, crop_y, crop_w, crop_h, out_file, limit
n_done = 0
for fname in args:
ser = AL.SerReader(fname, options.is_raw, options.mode)
for i in range(ser.count):
if limit > 0 and n_done >= limit:
return
im = ser.get()
if crop_w < 0:
crop_w = im[0].shape[0]
if crop_h < 0:
crop_h = im[0].shape[1]
if ser_out is None:
if options.is_raw:
color_id = ser.color_id
else:
color_id = None
ser_out = AL.SerWriter(out_file, (crop_w, crop_h) , len(im), color_id=color_id)
if options.is_register:
if len(im) == 1 :
imL = im[0]
else:
imL = 0.299 * im[0] + 0.587 * im[1] + 0.114 * im[2]
if ref is None:
ref = np.fft.fft2(imL)
else:
fft = np.fft.fft2(imL,s=ref.shape)
xshift,yshift = AL.registration_dft(ref, fft)
im = [np.roll(np.roll(i, xshift, axis=0), yshift, axis=1) for i in im]
im = [i[crop_x:(crop_x+crop_w),crop_y:(crop_y+crop_h)] for i in im]
ser_out.write_frame(im)
n_done = n_done + 1
process()
ser_out.close()