forked from starryalley/public-misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
startrail.py
130 lines (105 loc) · 4.83 KB
/
startrail.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python
from gimpfu import *
import glob, os
# inspired by: http://www.startrails.de/html/software.html
#
# ref: libgimp http://developer.gimp.org/api/2.0/libgimp/libgimp-gimpenums.html
# Gimp Python http://www.gimp.org/docs/python/index.html
# PDB http://oldhome.schmorp.de/marc/pdb/index.html
def startrail(file_pattern, dark_file_pattern, output_filename):
print "current work dir:", os.getcwd()
print "file_pattern:", file_pattern
print "dark_file_pattern:", dark_file_pattern
print "output_filename:", output_filename
print "================================"
print "Processing Dark Frames..."
darkframe = dark(dark_file_pattern)
# get list of all input images
output_image = None
patterns = file_pattern.split(" ")
file_list = []
for p in patterns:
file_list += glob.glob(p)
# now every files is in file_list, loop and process all
for fname in file_list:
print "Processing:", fname
image = pdb.gimp_file_load(fname, fname)
if output_image is None:
# create new image
drawable = image.active_layer
output_image = pdb.gimp_image_new (drawable.width, drawable.height, 0)
# empty layer
#layer = gimp.Layer(output_image, "new", drawable.width, drawable.height, RGBA_IMAGE, 100, NORMAL_MODE)
# tmp image for dark frame subtraction
tmp_image = pdb.gimp_image_new (image.active_layer.width, image.active_layer.height, 0)
layer = pdb.gimp_layer_new_from_drawable (image.active_layer, tmp_image)
tmp_image.add_layer(layer, -1)
dark_layer = pdb.gimp_layer_new_from_drawable (darkframe.active_layer, tmp_image)
pdb.gimp_layer_set_mode(dark_layer, 8) # enum GimpLayerModeEffects, GIMP_SUBTRACT_MODE == 8
tmp_image.add_layer(dark_layer, -1)
pdb.gimp_image_merge_visible_layers(tmp_image, 1)
# this is the layer after dark frame subtraction
layer = pdb.gimp_layer_new_from_drawable (tmp_image.active_layer, output_image)
pdb.gimp_layer_set_mode(layer, 10) # enum GimpLayerModeEffects, GIMP_LIGHTEN_ONLY_MODE == 10
output_image.add_layer(layer, -1)
# clean up
pdb.gimp_image_delete(image)
pdb.gimp_image_delete(tmp_image)
# save output image
if output_image is not None:
# EXPAND_AS_NECESSARY (0), CLIP_TO_IMAGE (1), CLIP_TO_BOTTOM_LAYER (2)
pdb.gimp_image_merge_visible_layers(output_image, 0)
print "Done! Save to", output_filename
pdb.gimp_file_save(output_image, output_image.active_layer, output_filename, output_filename)
pass
def dark(file_pattern):
#http://www.astromart.com/articles/article.asp?article_id=185
# get list of all dark images
output_image = None
patterns = file_pattern.split(" ")
file_list = []
for p in patterns:
file_list += glob.glob(p)
count = 1
# now every files is in file_list, loop and process all
for fname in file_list:
print "Processing Dark:", fname
image = pdb.gimp_file_load(fname, fname)
if output_image is None:
# create new image
drawable = image.active_layer
output_image = pdb.gimp_image_new (drawable.width, drawable.height, 0)
layer = pdb.gimp_layer_new_from_drawable (image.active_layer, output_image)
pdb.gimp_layer_set_opacity(layer, (1.0 / count * 100))
#print "[%d]Transparency: %.1f" %(count, (1.0 / count * 100))
count += 1
#pdb.gimp_layer_set_mode(layer, 10) # enum GimpLayerModeEffects, GIMP_LIGHTEN_ONLY_MODE == 10
output_image.add_layer(layer, -1) # -1 means to insert it above the active layer
#drawable = pdb.gimp_image_get_active_layer(image)
pdb.gimp_image_delete(image)
# save output image
if output_image is not None:
# EXPAND_AS_NECESSARY (0), CLIP_TO_IMAGE (1), CLIP_TO_BOTTOM_LAYER (2)
pdb.gimp_image_merge_visible_layers(output_image, 1)
pdb.gimp_file_save(output_image, output_image.active_layer, "dark.jpg", "dark.jpg")
print "Dark Frames done! Save to dark.jpg"
return output_image
#
register(
"startrail",
"Star Trail Maker v1.0",
"Merge multiple exposures (pictures) into one using ligten layer mode\n Exposures are supposed to be taken on a tripot with successive same exposures so that it makes the star trails.",
"Mark Kuo (starryalley@gmail.com)",
"Licensed under GPLv3",
"2010.10",
"<Toolbox>/Xtns/Languages/Python-Fu/Star Trail Maker",
"*",
[
(PF_STRING, "file_pattern", "Input File Pattern", "*.jpg"),
(PF_STRING, "dark_file_pattern", "Dark Frames Input File Pattern", "*.jpg"),
(PF_STRING, "output_filename", "Output Filename", "output.jpg"),
],
[],
startrail
)
main()