~ubuntu-branches/ubuntu/vivid/nip2/vivid-proposed

« back to all changes in this revision

Viewing changes to share/nip2/compat/7.16/Histogram.def

  • Committer: Bazaar Package Importer
  • Author(s): Michael Terry
  • Date: 2009-05-12 09:26:46 UTC
  • mfrom: (1.2.11 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090512092646-j8lb1w2x69pvgma4
Tags: 7.18.1-1ubuntu1
* Merge from debian unstable (LP: #375435), remaining changes:
  - debian/control: Also Recommend abrowser

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Hist_new_item = class
 
2
        Menupullright "_New" "new histogram" {
 
3
        Hist_item = class
 
4
                Menuaction "Histogram" "make an identity histogram" {
 
5
                action = class 
 
6
                        _result {
 
7
                        _vislevel = 3;
 
8
 
 
9
                        d = Option "Depth" ["8 bit", "16 bit"] 0;
 
10
                        _result = Plot [] ([im_identity 1, im_identity_ushort 1 65536]?d);
 
11
                }
 
12
        }
 
13
 
 
14
        Hist_new_from_matrix = Matrix_buildlut_item; 
 
15
 
 
16
        Hist_from_image_item = class
 
17
                Menuaction "Ta_g Image As Histogram" "set image Type field to Histogram" {
 
18
                action x = hist_tag x;
 
19
        }
 
20
 
 
21
        Tone_item = class 
 
22
                Menuaction "_Tone Curve" "make a new tone mapping curve" {
 
23
                action = class
 
24
                        _result {
 
25
                        _vislevel = 3;
 
26
 
 
27
                        d = Option "Depth" ["8 bit", "16 bit"] 0;
 
28
                        b = Scale "Black point"  0 100 0;
 
29
                        w = Scale "White point"  0 100 100;
 
30
 
 
31
                        sp = Scale "Shadow point" 0.1 0.3 0.2;
 
32
                        mp = Scale "Mid-tone point" 0.4 0.6 0.5;
 
33
                        hp = Scale "Highlight point" 0.7 0.9 0.8;
 
34
 
 
35
                        sa = Scale "Shadow adjust" (-15) 15 0;
 
36
                        ma = Scale "Mid-tone adjust" (-30) 30 0;
 
37
                        ha = Scale "Highlight adjust" (-15) 15 0;
 
38
 
 
39
                        _result 
 
40
                                = tone_build fmt b w sp mp hp sa ma ha
 
41
                        {
 
42
                                fmt = [Image_format.UCHAR, Image_format.USHORT]?d;
 
43
                        }
 
44
                }
 
45
        }
 
46
}
 
47
 
 
48
Hist_find_item = class 
 
49
        Menupullright "_Find" "find a histogram" {
 
50
        Oned_item = class 
 
51
                Menuaction "_One Dimension" 
 
52
                        "for a n-band image, make an n-band 1D histogram" {
 
53
                action x = map_unary hist_find x;
 
54
        }
 
55
 
 
56
        Nd_item = class 
 
57
                Menuaction "_Many Dimensions" 
 
58
                        "for a n-band image, make an n-dimensional histogram" {
 
59
                action x = class 
 
60
                        _result {
 
61
                        _vislevel = 3;
 
62
 
 
63
                        // default to something small-ish
 
64
                        bins = Expression "Number of bins in each dimension" 8;
 
65
 
 
66
                        _result 
 
67
                                = map_unary process x
 
68
                        {
 
69
                                process in
 
70
                                        = hist_find_nD bins in;
 
71
                        }
 
72
                }
 
73
        }
 
74
}
 
75
 
 
76
Hist_map_item = class 
 
77
        Menuaction "_Map Histogram" "map an image through a histogram" {
 
78
        action x y
 
79
                = map_binary map x y
 
80
        {
 
81
                map a b
 
82
                        = hist_map hist im
 
83
                {
 
84
                        [im, hist] = sortc (const is_hist) [a, b];
 
85
                }
 
86
        }
 
87
}
 
88
 
 
89
Hist_eq_item = Filter_enhance_item.Hist_equal_item;
 
90
 
 
91
#separator
 
92
 
 
93
Hist_cum_item = class 
 
94
        Menuaction "_Cumulativise Histogram" 
 
95
                "form cumulative histogram" {
 
96
        action x = map_unary hist_cum x;
 
97
}
 
98
 
 
99
Hist_diff_item = class 
 
100
        Menuaction "_Differentiate Histogram" 
 
101
                "find point-to-point differences (inverse of Cumulativise)" {
 
102
        action x = map_unary hist_diff x;
 
103
}
 
104
 
 
105
Hist_norm_item = class 
 
106
        Menuaction "N_ormalise Histogram" "normalise a histogram" {
 
107
        action x = map_unary hist_norm x;
 
108
}
 
109
 
 
110
Hist_match_item = class 
 
111
        Menuaction "Ma_tch Histogram" 
 
112
                "find LUT which will match first histogram to second" {
 
113
        action in ref = map_binary hist_match in ref;
 
114
}
 
115
 
 
116
Hist_zerox_item = class 
 
117
        Menuaction "_Zero Crossings" "find zero crossings" {
 
118
        action x = class 
 
119
                _result {
 
120
                _vislevel = 3;
 
121
 
 
122
                edge = Option "Direction" [
 
123
                        "Positive-going", 
 
124
                        "Negative-going"
 
125
                ] 0;
 
126
 
 
127
                _result 
 
128
                        = map_unary (zerox (if edge == 0 then -1 else 1)) x;
 
129
        }
 
130
}
 
131
 
 
132
#separator
 
133
 
 
134
Hist_profile_item = class 
 
135
        Menuaction "Find _Profile" 
 
136
                "search from image edges for non-zero pixels" {
 
137
        action x = class  
 
138
                _result {
 
139
                _vislevel = 3;
 
140
 
 
141
                edge = Option "Search from" [
 
142
                        "Top edge down", 
 
143
                        "Left edge to right",
 
144
                        "Bottom edge up",
 
145
                        "Right edge to left"
 
146
                ] 2;
 
147
 
 
148
                _result 
 
149
                        = map_unary profile x
 
150
                {
 
151
                        profile image
 
152
                                = (Plot_histogram @ hist_tag) [
 
153
                                        profilemb 0 image.value,
 
154
                                        profilemb 1 image.value,
 
155
                                        profilemb 0 (fliptb image.value),
 
156
                                        profilemb 1 (fliplr image.value)
 
157
                                ]?edge;
 
158
 
 
159
                        // im_profile only does 1 band images :-(
 
160
                        profilemb d = bandjoin @ map (converse im_profile d) @ bandsplit;
 
161
                }
 
162
        }
 
163
}
 
164
 
 
165
Hist_project_item = class 
 
166
        Menuaction "Find Pro_jections" 
 
167
                "find horizontal and vertical projections" {
 
168
        action x = class {
 
169
                _vislevel = 2;
 
170
 
 
171
                _result = map_unary project x;
 
172
 
 
173
                // extract the result ... could be a group
 
174
                extr n
 
175
                        = Plot_histogram _result?n, is_list _result
 
176
                        = Group (map (Plot_histogram @ converse subscript n) _result.value);
 
177
 
 
178
                horizontal = extr 0;
 
179
                vertical = extr 1;
 
180
                centre = (gravity horizontal, gravity vertical);
 
181
        }
 
182
}
 
183
 
 
184
#separator
 
185
 
 
186
Hist_graph_item = class 
 
187
        Menuaction "P_lot Slice" "plot a slice along a guide or arrow" {
 
188
        action x = class 
 
189
                _value {
 
190
                _vislevel = 3;
 
191
 
 
192
                width = Scale "Width" 1 40 1;
 
193
                displace = Scale "Horizontal displace" (-50) 50 0; 
 
194
                vdisplace = Scale "Vertical displace" (-50) 50 0; 
 
195
 
 
196
                _value
 
197
                        = map_unary graph x
 
198
                {
 
199
                        graph arrow
 
200
                                = hist_tag area'
 
201
                        {
 
202
                                // the line as a polar vector
 
203
                                pv = polar (arrow.width, arrow.height);
 
204
                                a = im pv;
 
205
 
 
206
                                // smallest rotation that will make the line horizontal
 
207
                                a'
 
208
                                        = 360 - a, a > 270
 
209
                                        = 180 - a, a > 90
 
210
                                        = -a;
 
211
 
 
212
                                im' = rotate a' arrow.image;
 
213
 
 
214
                                // look at the start and end of the arrow, pick the leftmost
 
215
                                p
 
216
                                        = (arrow.left, arrow.top), arrow.left <= arrow.right
 
217
                                        = (arrow.right, arrow.bottom);
 
218
 
 
219
                                // transform that point to im' space
 
220
                                p' = rectangular (polar p + (0, a')) + 
 
221
                                        (im'.xoffset, im'.yoffset);
 
222
 
 
223
                                // extract that area
 
224
                                area = extract_area 
 
225
                                        (re p' + displace.value) 
 
226
                                        (im p' - width.value / 2 + vdisplace.value) 
 
227
                                        (re pv) width.value 
 
228
                                        im';
 
229
 
 
230
                                // squish vertically to get an average
 
231
                                area' = resize 1 (1 / width.value) Interpolate.BILINEAR area;
 
232
                        }
 
233
                }
 
234
        }
 
235
}
 
236
 
 
237
Extract_arrow_item = class 
 
238
        Menuaction "Extract _Arrow" "extract the area around an arrow" {
 
239
        action x = class 
 
240
                _value {
 
241
                _vislevel = 3;
 
242
 
 
243
                width = Scale "Width" 1 40 1;
 
244
                displace = Scale "Horizontal displace" (-50) 50 0; 
 
245
                vdisplace = Scale "Vertical displace" (-50) 50 0; 
 
246
 
 
247
                _value
 
248
                        = map_unary graph x
 
249
                {
 
250
                        graph arrow
 
251
                                = area
 
252
                        {
 
253
                                // the line as a polar vector
 
254
                                pv = polar (arrow.width, arrow.height);
 
255
                                a = im pv;
 
256
 
 
257
                                // smallest rotation that will make the line horizontal
 
258
                                a'
 
259
                                        = 360 - a, a > 270
 
260
                                        = 180 - a, a > 90
 
261
                                        = -a;
 
262
 
 
263
                                im' = rotate a' arrow.image;
 
264
 
 
265
                                // look at the start and end of the arrow, pick the leftmost
 
266
                                p
 
267
                                        = (arrow.left, arrow.top), arrow.left <= arrow.right
 
268
                                        = (arrow.right, arrow.bottom);
 
269
 
 
270
                                // transform that point to im' space
 
271
                                p' = rectangular (polar p + (0, a')) + 
 
272
                                        (im'.xoffset, im'.yoffset);
 
273
 
 
274
                                // extract that area
 
275
                                area = extract_area 
 
276
                                        (re p' + displace.value) 
 
277
                                        (im p' - width.value / 2 + vdisplace.value) 
 
278
                                        (re pv) width.value 
 
279
                                        im';
 
280
                        }
 
281
                }
 
282
        }
 
283
}
 
284
 
 
285
Hist_plot_item = class
 
286
        Menuaction "Plot _Object" 
 
287
                "plot an object as a bar, point or line graph" {
 
288
        action x = class
 
289
                _result {
 
290
                _vislevel = 3;
 
291
 
 
292
                format = Option_enum Plot_format.names "Format" "YYYY";
 
293
                style = Option_enum Plot_style.names "Style" "Line";
 
294
 
 
295
                auto = Toggle "Auto Range" true;
 
296
                xmin = Expression "X range minimum" 0;
 
297
                xmax = Expression "X range maximum" 1;
 
298
                ymin = Expression "Y range minimum" 0;
 
299
                ymax = Expression "Y range maximum" 1;
 
300
 
 
301
                _result
 
302
                        = Plot options (image x)
 
303
                {
 
304
                        options
 
305
                                = [$style => style.value, $format => format.value] ++ range;
 
306
                        range
 
307
                                = [], auto
 
308
                                = [$xmin => xmin.expr, $xmax => xmax.expr, 
 
309
                                        $ymin => ymin.expr, $ymax => ymax.expr]; 
 
310
 
 
311
                        image x
 
312
                                = image (extract_arrow x), is_Arrow x
 
313
                                = get_image x, has_image x
 
314
                                = x2b im, b == 1
 
315
                                = im
 
316
                        {
 
317
                                im = get_image (to_image x);
 
318
                                w = get_width im;
 
319
                                h = get_height im;
 
320
                                b = get_bands im;
 
321
 
 
322
                                // matrix to image makes a 1-band mxn image
 
323
                                // we need to put columns into bands
 
324
                                x2b im 
 
325
                                        = bandjoin (map extract_col [0 .. w - 1])
 
326
                                {
 
327
                                                extract_col x = extract_area x 0 1 h im;
 
328
                                }
 
329
                        }
 
330
 
 
331
                        extract_arrow arrow
 
332
                                = extract_area (re p') (im p') (re pv) 1 im'
 
333
                        {
 
334
                                // the line as a polar vector
 
335
                                pv = polar (arrow.width, arrow.height);
 
336
                                a = im pv;
 
337
 
 
338
                                // smallest rotation that will make the line horizontal
 
339
                                a'
 
340
                                        = 360 - a, a > 270
 
341
                                        = 180 - a, a > 90
 
342
                                        = -a;
 
343
 
 
344
                                im' = rotate a' arrow.image;
 
345
 
 
346
                                // look at the start and end of the arrow, pick the leftmost
 
347
                                p
 
348
                                        = (arrow.left, arrow.top), arrow.left <= arrow.right
 
349
                                        = (arrow.right, arrow.bottom);
 
350
 
 
351
                                // transform that point to im' space
 
352
                                p' = rectangular (polar p + (0, a')) + 
 
353
                                        (im'.xoffset, im'.yoffset);
 
354
                        }
 
355
                }
 
356
        }
 
357
}