5 import gfxprim
.core
as core
6 import gfxprim
.loaders
as loaders
7 import gfxprim
.filters
as filters
15 def to_str(x
, to_str
):
17 if hasattr(x
, '__iter__'):
19 if hasattr(i
, '__iter__'):
30 res
+= ('(' + to_str(i
)+ ')')
37 def __init__(self
, orig_path
):
38 self
.orig_path
= orig_path
39 self
.img
= loaders
.Load('../' + orig_path
+ 'lenna.png')
40 self
.img_small
= loaders
.Load('../' + orig_path
+ 'lenna_small.png')
42 def write_asciidoc_head(self
, dst_path
, heading
):
43 self
.f
= open('../' + dst_path
+ 'images.txt', 'w')
45 f
.write('.Original Image; ' + heading
+ '\n')
46 f
.write('image:' + self
.orig_path
+ 'lenna_small.png[\n')
47 f
.write('\t"Original Image",\n')
48 f
.write('\tlink="' + self
.orig_path
+ 'lenna.png"]\n')
50 def write_img_asciidoc(self
, desc
, fname
, fname_small
):
52 f
.write('image:' + fname_small
+ '[\n')
53 f
.write('\t"' + desc
+ '",\n')
54 f
.write('\tlink="' + fname
+ '"]\n')
56 def write_asciidoc_tail(self
):
60 def gen(self
, func
, func_param_desc
, func_params_arr
, dst_path
, func_name
, descs
=None):
62 print("Generating " + func_name
)
64 head
= func_name
+ ' '
65 head
+= ', '.join(map(lambda x
: ' '.join([func_param_desc
[i
] + '=' +
66 str(x
[i
]) for i
in range(0, len(x
))]), func_params_arr
))
68 if (descs
is not None):
69 head
= ', '.join(descs
)
71 self
.write_asciidoc_head(dst_path
, head
)
73 for i
in range(0, len(func_params_arr
)):
74 params
= func_params_arr
[i
]
75 str_pars
= [to_str(x
, str) for x
in params
]
77 if (descs
is not None):
80 desc
= func_name
+ ' ' + ' '.join(str_pars
)
84 fname
= dst_path
+ 'lenna_' + ','.join(str_pars
) + '.png'
85 fname_small
= dst_path
+ 'lenna_small_' + ','.join(str_pars
) + '.png'
87 self
.write_img_asciidoc(desc
, fname
, fname_small
)
89 res
= func(self
.img
, *params
)
90 res
.loaders
.Save('../' + fname
)
92 res
= func(self
.img_small
, *params
)
93 res
.loaders
.Save('../' + fname_small
)
95 self
.write_asciidoc_tail()
98 imggen
= ImgGen('images/orig/')
100 imggen
.gen(filters
.InvertAlloc
, [],
102 'images/invert/', 'Inverted')
104 imggen
.gen(filters
.BrightnessAlloc
, ['p'],
105 [[-.5], [-.2], [.2], [.5]],
106 'images/brightness/', 'Brightness')
108 imggen
.gen(filters
.ContrastAlloc
, ['p'],
109 [[.2], [.5], [1.5], [2], [3]],
110 'images/contrast/', 'Contrast')
112 imggen
.gen(filters
.BrightnessContrastAlloc
, ['b', 'c'],
113 [[-.2, .8], [-.5, 2], [.2, .8], [.2, 1.5]],
114 'images/brightness_contrast/', 'BrightnessContrast')
116 imggen
.gen(filters
.PosterizeAlloc
, ['s'],
117 [[2], [3], [4], [5], [6]],
118 'images/posterize/', 'Posterize')
120 imggen
.gen(filters
.MirrorHAlloc
, [],
122 'images/mirror_h/', 'Mirrored Horizontally')
124 imggen
.gen(filters
.MirrorVAlloc
, [],
126 'images/mirror_v/', 'Mirrored Vertically')
128 imggen
.gen(filters
.Rotate90Alloc
, [],
130 'images/rotate_90/', 'Rotated by 90 degrees')
132 imggen
.gen(filters
.Rotate180Alloc
, [],
134 'images/rotate_180/', 'Rotated by 180 degrees')
136 imggen
.gen(filters
.Rotate270Alloc
, [],
138 'images/rotate_270/', 'Rotated by 270 degrees')
140 imggen
.gen(filters
.GaussianBlurAlloc
, ['xsig', 'ysig'],
141 [[2, 2], [0, 4], [4, 0], [4, 4], [10, 10]],
142 'images/blur/', 'Gaussian Blur')
144 imggen
.gen(filters
.MedianAlloc
, ['xr', 'yr'],
145 [[3, 3], [5, 5], [7, 7], [9, 9], [12, 12]],
146 'images/median/', 'Median')
148 imggen
.gen(filters
.EdgeSharpeningAlloc
, ['w'],
149 [[0.1], [0.3], [0.5], [0.8], [1.0]],
150 'images/edge_sharpening/', 'Edge Sharpening')
152 imggen
.gen(filters
.GaussianNoiseAddAlloc
, ['s', 'm'],
153 [[0.03, 0], [0.05, 0], [0.05, -0.1], [0.05, 0.1], [0.07, 0.0]],
154 'images/gaussian_noise/', 'Gaussian Additive Noise')
156 imggen
.gen(filters
.ConvolutionAlloc
, ['k', 'kd'],
165 [1, 1, 1, 1, 1]], 25],
176 'images/convolution/', 'Convolution',
183 if __name__
== '__main__':