ruby-vips 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +31 -0
- data/LICENSE +20 -0
- data/README.md +96 -0
- data/TODO +18 -0
- data/ext/extconf.rb +10 -0
- data/ext/header.c +440 -0
- data/ext/header.h +8 -0
- data/ext/image.c +639 -0
- data/ext/image.h +71 -0
- data/ext/image_arithmetic.c +940 -0
- data/ext/image_arithmetic.h +38 -0
- data/ext/image_boolean.c +302 -0
- data/ext/image_boolean.h +8 -0
- data/ext/image_colour.c +593 -0
- data/ext/image_colour.h +36 -0
- data/ext/image_conversion.c +863 -0
- data/ext/image_conversion.h +37 -0
- data/ext/image_convolution.c +371 -0
- data/ext/image_convolution.h +13 -0
- data/ext/image_freq_filt.c +742 -0
- data/ext/image_freq_filt.h +27 -0
- data/ext/image_histograms_lut.c +646 -0
- data/ext/image_histograms_lut.h +28 -0
- data/ext/image_morphology.c +330 -0
- data/ext/image_morphology.h +13 -0
- data/ext/image_mosaicing.c +556 -0
- data/ext/image_mosaicing.h +14 -0
- data/ext/image_relational.c +386 -0
- data/ext/image_relational.h +8 -0
- data/ext/image_resample.c +253 -0
- data/ext/image_resample.h +9 -0
- data/ext/interpolator.c +106 -0
- data/ext/interpolator.h +6 -0
- data/ext/mask.c +349 -0
- data/ext/mask.h +17 -0
- data/ext/reader.c +315 -0
- data/ext/ruby_vips.c +131 -0
- data/ext/ruby_vips.h +26 -0
- data/ext/writer.c +346 -0
- data/lib/vips.rb +7 -0
- data/lib/vips/reader.rb +183 -0
- data/lib/vips/version.rb +3 -0
- data/lib/vips/writer.rb +275 -0
- data/ruby-vips.gemspec +93 -0
- metadata +163 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
VALUE img_fwfft(VALUE);
|
2
|
+
VALUE img_invfft(VALUE);
|
3
|
+
VALUE img_rotquad(VALUE);
|
4
|
+
VALUE img_invfftr(VALUE);
|
5
|
+
VALUE img_s_fmask_ideal_highpass(VALUE, VALUE, VALUE, VALUE);
|
6
|
+
VALUE img_s_fmask_ideal_lowpass(VALUE, VALUE, VALUE, VALUE);
|
7
|
+
VALUE img_s_fmask_butterworth_highpass(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
8
|
+
VALUE img_s_fmask_butterworth_lowpass(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
9
|
+
VALUE img_s_fmask_gauss_highpass(VALUE, VALUE, VALUE, VALUE, VALUE);
|
10
|
+
VALUE img_s_fmask_gauss_lowpass(VALUE, VALUE, VALUE, VALUE, VALUE);
|
11
|
+
VALUE img_s_fmask_ideal_ringpass(VALUE, VALUE, VALUE, VALUE, VALUE);
|
12
|
+
VALUE img_s_fmask_ideal_ringreject(VALUE, VALUE, VALUE, VALUE, VALUE);
|
13
|
+
VALUE img_s_fmask_butterworth_ringpass(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
14
|
+
VALUE img_s_fmask_butterworth_ringreject(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
15
|
+
VALUE img_s_fmask_gauss_ringpass(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
16
|
+
VALUE img_s_fmask_gauss_ringreject(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
17
|
+
VALUE img_s_fmask_ideal_bandpass(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
18
|
+
VALUE img_s_fmask_ideal_bandreject(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
19
|
+
VALUE img_s_fmask_butterworth_bandpass(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
20
|
+
VALUE img_s_fmask_butterworth_bandreject(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
21
|
+
VALUE img_s_fmask_gauss_bandpass(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
22
|
+
VALUE img_s_fmask_gauss_bandreject(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
23
|
+
VALUE img_s_fmask_fractal_flt(VALUE, VALUE, VALUE, VALUE);
|
24
|
+
VALUE img_freqflt(VALUE, VALUE);
|
25
|
+
VALUE img_disp_ps(VALUE);
|
26
|
+
VALUE img_phasecor_fft(VALUE, VALUE);
|
27
|
+
VALUE img_s_fractsurf(VALUE, VALUE, VALUE);
|
@@ -0,0 +1,646 @@
|
|
1
|
+
#include "ruby_vips.h"
|
2
|
+
#include "image.h"
|
3
|
+
#include "mask.h"
|
4
|
+
#include "image_histograms_lut.h"
|
5
|
+
|
6
|
+
/*
|
7
|
+
* call-seq:
|
8
|
+
* im.histgr([band]) -> image
|
9
|
+
*
|
10
|
+
* Find the histogram of *self*. If <i>band</i> is given, find the histogram
|
11
|
+
* for that band (producing a one-band histogram). If <i>band</i> is not given,
|
12
|
+
* find the histogram for all bands (producing an n-band histogram).
|
13
|
+
*
|
14
|
+
* *self* must be u8 or u16. The output image is always u32.
|
15
|
+
*/
|
16
|
+
|
17
|
+
VALUE
|
18
|
+
img_histgr(int argc, VALUE *argv, VALUE obj)
|
19
|
+
{
|
20
|
+
VALUE v_bandno;
|
21
|
+
int bandno;
|
22
|
+
GetImg(obj, data, im);
|
23
|
+
OutImg(obj, new, data_new, im_new);
|
24
|
+
|
25
|
+
rb_scan_args(argc, argv, "01", &v_bandno);
|
26
|
+
bandno = NIL_P(v_bandno) ? -1 : NUM2INT(v_bandno);
|
27
|
+
|
28
|
+
if (im_histgr(im, im_new, bandno))
|
29
|
+
vips_lib_error();
|
30
|
+
|
31
|
+
return new;
|
32
|
+
}
|
33
|
+
|
34
|
+
/*
|
35
|
+
* call-seq:
|
36
|
+
* im.histnd(bins) -> image
|
37
|
+
*
|
38
|
+
* Make a one, two or three dimensional histogram of a 1, 2 or 3 band image.
|
39
|
+
* Divide each axis into a certain number of bins .. ie. output is 1 x bins,
|
40
|
+
* bins x bins, or bins x bins x bins bands. uchar and ushort only.
|
41
|
+
*/
|
42
|
+
|
43
|
+
VALUE
|
44
|
+
img_histnd(VALUE obj, VALUE bins)
|
45
|
+
{
|
46
|
+
GetImg(obj, data, im);
|
47
|
+
OutImg(obj, new, data_new, im_new);
|
48
|
+
|
49
|
+
if (im_histnD(im, im_new, NUM2INT(bins)))
|
50
|
+
vips_lib_error();
|
51
|
+
|
52
|
+
return new;
|
53
|
+
}
|
54
|
+
|
55
|
+
/*
|
56
|
+
* call-seq:
|
57
|
+
* im.hist_indexed(other_image) -> image
|
58
|
+
*
|
59
|
+
* Make a histogram of <i>other_image</i>, but use *self* to pick the bins. In
|
60
|
+
* other words, element zero in the output image contains the sum of all the
|
61
|
+
* pixels in <i>other_image</i> whose corresponding pixel in *self* is zero.
|
62
|
+
*
|
63
|
+
* *self* must have just one band and be u8 or u16. <i>other_image</i> must be
|
64
|
+
* non-complex. The output image always has the same size and format as
|
65
|
+
* <i>other_image</i>.
|
66
|
+
*
|
67
|
+
* This operation is useful in conjunction with Image#label_regions. You can
|
68
|
+
* use it to find the centre of gravity of blobs in an image, for example.
|
69
|
+
*/
|
70
|
+
|
71
|
+
VALUE
|
72
|
+
img_hist_indexed(VALUE obj, VALUE obj2)
|
73
|
+
{
|
74
|
+
RUBY_VIPS_BINARY(im_hist_indexed);
|
75
|
+
}
|
76
|
+
|
77
|
+
/*
|
78
|
+
* call-seq:
|
79
|
+
* Image.identity(bands) -> image
|
80
|
+
*
|
81
|
+
* Creates a image file with Xsize=256, Ysize=1, Bands=<i>bands</i>,
|
82
|
+
* BandFmt= :UCHAR, Type=:HISTOGRAM.
|
83
|
+
*
|
84
|
+
* The created image consist of a <i>bands</i>-bands linear lut and is the
|
85
|
+
* basis for building up look-up tables.
|
86
|
+
*/
|
87
|
+
|
88
|
+
VALUE
|
89
|
+
img_s_identity(VALUE obj, VALUE bands)
|
90
|
+
{
|
91
|
+
OutPartial(new, data, im);
|
92
|
+
|
93
|
+
if (im_identity(im, NUM2INT(bands)))
|
94
|
+
vips_lib_error();
|
95
|
+
|
96
|
+
return new;
|
97
|
+
}
|
98
|
+
|
99
|
+
/*
|
100
|
+
* call-seq:
|
101
|
+
* Image.identity_ushort(size) -> image
|
102
|
+
*
|
103
|
+
* As Image.identity, but make a ushort LUT. ushort LUTs can be up to 65536
|
104
|
+
* elements - <i>size</i> is the number of elements required.
|
105
|
+
*
|
106
|
+
* The created image consist of a <i>bands</i>-bands linear lut and is the
|
107
|
+
* basis for building up look-up tables.
|
108
|
+
*/
|
109
|
+
|
110
|
+
VALUE
|
111
|
+
img_s_identity_ushort(VALUE obj, VALUE bands, VALUE sz)
|
112
|
+
{
|
113
|
+
OutPartial(new, data, im);
|
114
|
+
|
115
|
+
if (im_identity_ushort(im, NUM2INT(bands), NUM2INT(sz)))
|
116
|
+
vips_lib_error();
|
117
|
+
|
118
|
+
return new;
|
119
|
+
}
|
120
|
+
|
121
|
+
/*
|
122
|
+
* call-seq:
|
123
|
+
* Image.invertlut(input, lut_size) -> image
|
124
|
+
*
|
125
|
+
* Given a <i>input</i> of target values and real values, generate a LUT which
|
126
|
+
* will map reals to targets. Handy for linearising images from measurements of
|
127
|
+
* a colour chart. All values in [0,1]. Piecewise linear interpolation,
|
128
|
+
* extrapolate head and tail to 0 and 1.
|
129
|
+
*
|
130
|
+
* Eg. input like this:
|
131
|
+
*
|
132
|
+
* input = [
|
133
|
+
* [0.2, 0.2, 0.3, 0.1],
|
134
|
+
* [0.2, 0.4, 0.4, 0.2],
|
135
|
+
* [0.7, 0.5, 0.6, 0.3]
|
136
|
+
* ]
|
137
|
+
*
|
138
|
+
* Means a patch with 10% reflectance produces an image with 20% in channel 1,
|
139
|
+
* 30% in channel 2, and 10% in channel 3, and so on.
|
140
|
+
*
|
141
|
+
* Inputs don't need to be sorted (we do that). Generate any precision LUT,
|
142
|
+
* typically you might ask for 256 elements.
|
143
|
+
*
|
144
|
+
* It won't work too well for non-monotonic camera responses.
|
145
|
+
*
|
146
|
+
* <i>input</i> can be an array or a Mask object.
|
147
|
+
*/
|
148
|
+
|
149
|
+
VALUE
|
150
|
+
img_s_invertlut(VALUE obj, VALUE input, VALUE lut_size)
|
151
|
+
{
|
152
|
+
DOUBLEMASK *dmask;
|
153
|
+
OutPartial(new, data, im);
|
154
|
+
|
155
|
+
mask_arg2mask(input, NULL, &dmask);
|
156
|
+
|
157
|
+
if (im_invertlut(dmask, im, NUM2INT(lut_size)))
|
158
|
+
vips_lib_error();
|
159
|
+
|
160
|
+
return new;
|
161
|
+
}
|
162
|
+
|
163
|
+
/*
|
164
|
+
* call-seq:
|
165
|
+
* Image.buildlut(input) -> image
|
166
|
+
*
|
167
|
+
* This operation builds a lookup table from a set of points. Intermediate
|
168
|
+
* values are generated by piecewise linear interpolation.
|
169
|
+
*
|
170
|
+
* For example, consider this 2 x 2 matrix of (x, y) coordinates:
|
171
|
+
*
|
172
|
+
* input = [
|
173
|
+
* [ 0, 0],
|
174
|
+
* [255, 100]
|
175
|
+
* ]
|
176
|
+
* im = Image.invertlut(input)
|
177
|
+
*
|
178
|
+
* We then generate an image with the following pixel values:
|
179
|
+
*
|
180
|
+
* im[0, 0] # => 0
|
181
|
+
* im[0, 1] # => 0.4
|
182
|
+
* # ...
|
183
|
+
* im[0, 255] # => 100
|
184
|
+
*
|
185
|
+
* This is then written as the output image, with the left column giving the
|
186
|
+
* index in the image to place the value.
|
187
|
+
*
|
188
|
+
* The (x, y) points don't need to be sorted: we do that. You can have several
|
189
|
+
* Ys, each becomes a band in the output LUT. You don't need to start at zero,
|
190
|
+
* any integer will do, including negatives.
|
191
|
+
*/
|
192
|
+
|
193
|
+
VALUE
|
194
|
+
img_s_buildlut(VALUE obj, VALUE input)
|
195
|
+
{
|
196
|
+
DOUBLEMASK *dmask;
|
197
|
+
OutPartial(new, data, im);
|
198
|
+
|
199
|
+
mask_arg2mask(input, NULL, &dmask);
|
200
|
+
|
201
|
+
if (im_buildlut(dmask, im))
|
202
|
+
vips_lib_error();
|
203
|
+
|
204
|
+
return new;
|
205
|
+
}
|
206
|
+
|
207
|
+
/*
|
208
|
+
* call-seq:
|
209
|
+
* im.project -> image
|
210
|
+
*
|
211
|
+
* Find the horizontal and vertical projections of an image, ie. the sum
|
212
|
+
* of every row of pixels, and the sum of every column of pixels. The output
|
213
|
+
* format is uint, int or double, depending on the input format.
|
214
|
+
*
|
215
|
+
* Non-complex images only.
|
216
|
+
*/
|
217
|
+
|
218
|
+
VALUE
|
219
|
+
img_project(VALUE obj)
|
220
|
+
{
|
221
|
+
GetImg(obj, data, im);
|
222
|
+
OutImg(obj, new, data_new, im_new);
|
223
|
+
OutImg(obj, new2, data_new2, im_new2);
|
224
|
+
|
225
|
+
if (im_project(im, im_new, im_new2))
|
226
|
+
vips_lib_error();
|
227
|
+
|
228
|
+
return rb_ary_new3(2, new, new2);
|
229
|
+
}
|
230
|
+
|
231
|
+
/*
|
232
|
+
* call-seq:
|
233
|
+
* im.histnorm -> image
|
234
|
+
*
|
235
|
+
* Normalise histogram ... normalise range to make it square (ie. max ==
|
236
|
+
* number of elements). Normalise each band separately.
|
237
|
+
*/
|
238
|
+
|
239
|
+
VALUE
|
240
|
+
img_histnorm(VALUE obj)
|
241
|
+
{
|
242
|
+
RUBY_VIPS_UNARY(im_histnorm);
|
243
|
+
}
|
244
|
+
|
245
|
+
/*
|
246
|
+
* call-seq:
|
247
|
+
* im.histcum -> image
|
248
|
+
*
|
249
|
+
* Form cumulative histogram.
|
250
|
+
*/
|
251
|
+
|
252
|
+
VALUE
|
253
|
+
img_histcum(VALUE obj)
|
254
|
+
{
|
255
|
+
RUBY_VIPS_UNARY(im_histcum);
|
256
|
+
}
|
257
|
+
|
258
|
+
/*
|
259
|
+
* call-seq:
|
260
|
+
* im.histeq -> image
|
261
|
+
*
|
262
|
+
* Histogram equalisation: normalised cumulative histogram.
|
263
|
+
*/
|
264
|
+
|
265
|
+
VALUE
|
266
|
+
img_histeq(VALUE obj)
|
267
|
+
{
|
268
|
+
RUBY_VIPS_UNARY(im_histeq);
|
269
|
+
}
|
270
|
+
|
271
|
+
/*
|
272
|
+
* call-seq:
|
273
|
+
* im.histspec(other_image) -> image
|
274
|
+
*
|
275
|
+
* Creates a lut which, when applied to the image from which histogram *self*
|
276
|
+
* was formed, will produce an image whose PDF matches that of the image from
|
277
|
+
* which <i>other_image</i> was formed.
|
278
|
+
*/
|
279
|
+
|
280
|
+
VALUE
|
281
|
+
img_histspec(VALUE obj, VALUE obj2)
|
282
|
+
{
|
283
|
+
RUBY_VIPS_BINARY(im_histspec);
|
284
|
+
}
|
285
|
+
|
286
|
+
/*
|
287
|
+
* call-seq:
|
288
|
+
* im.maplut(lut) -> image
|
289
|
+
*
|
290
|
+
* Map an image through another image acting as a LUT (Look Up Table).
|
291
|
+
* The lut may have any type, and the output image will be that type.
|
292
|
+
*
|
293
|
+
* The input image will be cast to one of the unsigned integer types, that is,
|
294
|
+
* band format :UCHAR, :USHORT or :UINT.
|
295
|
+
*
|
296
|
+
* If <i>lut</i> is too small for the input type (for example, if *self* is
|
297
|
+
* band format :UCHAR but <i>lut</i> only has 100 elements), the lut is padded
|
298
|
+
* out by copying the last element. Overflows are reported at the end of
|
299
|
+
* computation.
|
300
|
+
*
|
301
|
+
* If <i>lut</i> is too large, extra values are ignored.
|
302
|
+
*
|
303
|
+
* If <i>lut</i> has one band, then all bands of *self* pass through it. If
|
304
|
+
* <i>lut</i> has same number of bands as *self*, then each band is mapped
|
305
|
+
* separately. If *self* has one band, then @lut may have many bands and the
|
306
|
+
* output will have the same number of bands as <i>lut</i>.
|
307
|
+
*/
|
308
|
+
|
309
|
+
VALUE
|
310
|
+
img_maplut(VALUE obj, VALUE obj2)
|
311
|
+
{
|
312
|
+
GetImg(obj, data, im);
|
313
|
+
GetImg(obj2, data2, im2);
|
314
|
+
OutImg2(obj, obj2, new, data_new, im_new);
|
315
|
+
|
316
|
+
if (im_maplut(im, im_new, im2))
|
317
|
+
vips_lib_error();
|
318
|
+
|
319
|
+
return new;
|
320
|
+
}
|
321
|
+
|
322
|
+
/*
|
323
|
+
* call-seq:
|
324
|
+
* im.histplot -> image
|
325
|
+
*
|
326
|
+
* Plot a 1 by any or any by 1 image as a max by any or any by max image using
|
327
|
+
* these rules:
|
328
|
+
*
|
329
|
+
* * unsigned char max is always 256
|
330
|
+
* * other unsigned integer types output 0 - maxium value of *self*.
|
331
|
+
* * signed int types - min moved to 0, max moved to max + min.
|
332
|
+
* * float types - min moved to 0, max moved to any (square output).
|
333
|
+
*/
|
334
|
+
|
335
|
+
VALUE
|
336
|
+
img_histplot(VALUE obj)
|
337
|
+
{
|
338
|
+
RUBY_VIPS_UNARY(im_histplot);
|
339
|
+
}
|
340
|
+
|
341
|
+
/*
|
342
|
+
* call-seq:
|
343
|
+
* im.monotonic? -> true or false
|
344
|
+
*
|
345
|
+
* Test *self* for monotonicity. Returns true if *self* is monotonic.
|
346
|
+
*/
|
347
|
+
|
348
|
+
VALUE
|
349
|
+
img_monotonic_p(VALUE obj)
|
350
|
+
{
|
351
|
+
int ret;
|
352
|
+
GetImg(obj, data, im);
|
353
|
+
|
354
|
+
if( im_ismonotonic(im, &ret) )
|
355
|
+
vips_lib_error();
|
356
|
+
|
357
|
+
return( ret == 0 ? Qtrue : Qfalse );
|
358
|
+
}
|
359
|
+
|
360
|
+
/*
|
361
|
+
* call-seq:
|
362
|
+
* im.hist([band])
|
363
|
+
*
|
364
|
+
* Find and plot the histogram of *self*. If <i>band</i> is not given, plot all
|
365
|
+
* bands. Otherwise plot the specified band.
|
366
|
+
*/
|
367
|
+
|
368
|
+
VALUE
|
369
|
+
img_hist(int argc, VALUE *argv, VALUE obj)
|
370
|
+
{
|
371
|
+
VALUE v_bandno;
|
372
|
+
int bandno;
|
373
|
+
GetImg(obj, data, im);
|
374
|
+
OutImg(obj, new, data_new, im_new);
|
375
|
+
|
376
|
+
rb_scan_args(argc, argv, "01", &v_bandno);
|
377
|
+
bandno = NIL_P(v_bandno) ? -1 : NUM2INT(v_bandno);
|
378
|
+
|
379
|
+
if (im_hist(im, im_new, bandno))
|
380
|
+
vips_lib_error();
|
381
|
+
|
382
|
+
return new;
|
383
|
+
}
|
384
|
+
|
385
|
+
/*
|
386
|
+
* call-seq:
|
387
|
+
* im.hsp(other_image) -> image
|
388
|
+
*
|
389
|
+
* Maps *self* to the output image,, adjusting the histogram to match image
|
390
|
+
* <i>other_image</i>.
|
391
|
+
*
|
392
|
+
* Both images should have the same number of bands.
|
393
|
+
*/
|
394
|
+
|
395
|
+
VALUE
|
396
|
+
img_hsp(VALUE obj, VALUE obj2)
|
397
|
+
{
|
398
|
+
RUBY_VIPS_BINARY(im_hsp);
|
399
|
+
}
|
400
|
+
|
401
|
+
/*
|
402
|
+
* call-seq:
|
403
|
+
* im.gammacorrect(exponent) -> image
|
404
|
+
*
|
405
|
+
* Gamma-correct an 8- or 16-bit unsigned image with a lookup table. The
|
406
|
+
* output format is the same as the input format.
|
407
|
+
*/
|
408
|
+
|
409
|
+
VALUE
|
410
|
+
img_gammacorrect(VALUE obj, VALUE exponent)
|
411
|
+
{
|
412
|
+
GetImg(obj, data, im);
|
413
|
+
OutImg(obj, new, data_new, im_new);
|
414
|
+
|
415
|
+
if (im_gammacorrect(im, im_new, NUM2DBL(exponent)))
|
416
|
+
vips_lib_error();
|
417
|
+
|
418
|
+
return new;
|
419
|
+
}
|
420
|
+
|
421
|
+
/*
|
422
|
+
* call-seq:
|
423
|
+
* im.mpercent_hist(percent) -> number
|
424
|
+
*
|
425
|
+
* Just like Image#mpercent, except it works on an image histogram. Handy if
|
426
|
+
* you want to run Image#mpercent several times without having to recompute the
|
427
|
+
* histogram each time.
|
428
|
+
*/
|
429
|
+
|
430
|
+
VALUE
|
431
|
+
img_mpercent_hist(VALUE obj, VALUE percent)
|
432
|
+
{
|
433
|
+
#if IM_MAJOR_VERSION > 7 || IM_MINOR_VERSION >= 22
|
434
|
+
int ret;
|
435
|
+
GetImg(obj, data, im);
|
436
|
+
|
437
|
+
if (im_mpercent_hist(im, NUM2DBL(percent), &ret))
|
438
|
+
vips_lib_error();
|
439
|
+
|
440
|
+
return INT2NUM(ret);
|
441
|
+
#else
|
442
|
+
rb_raise(eVIPSError, "This operation is not supported by your version of VIPS");
|
443
|
+
#endif
|
444
|
+
}
|
445
|
+
|
446
|
+
/*
|
447
|
+
* call-seq:
|
448
|
+
* im.mpercent(percent) -> number
|
449
|
+
*
|
450
|
+
* Returns the threshold above which there are <i>percent</i> values of *self*.
|
451
|
+
* If for example percent=.1, the number of pels of the input image with values
|
452
|
+
* greater than the returned int will correspond to 10% of all pels of the
|
453
|
+
* image.
|
454
|
+
*
|
455
|
+
* The function works for uchar and ushort images only. It can be used to
|
456
|
+
* threshold the scaled result of a filtering operation.
|
457
|
+
*/
|
458
|
+
|
459
|
+
VALUE
|
460
|
+
img_mpercent(VALUE obj, VALUE percent)
|
461
|
+
{
|
462
|
+
int ret;
|
463
|
+
GetImg(obj, data, im);
|
464
|
+
|
465
|
+
if (im_mpercent(im, NUM2DBL(percent), &ret))
|
466
|
+
vips_lib_error();
|
467
|
+
|
468
|
+
return INT2NUM(ret);
|
469
|
+
}
|
470
|
+
|
471
|
+
/*
|
472
|
+
* call-seq:
|
473
|
+
* im.heq([band]) -> image
|
474
|
+
*
|
475
|
+
* Histogram-equalise *self*. Equalise using band <i>band</i>, or if not given,
|
476
|
+
* equalise all bands.
|
477
|
+
*/
|
478
|
+
|
479
|
+
VALUE
|
480
|
+
img_heq(int argc, VALUE *argv, VALUE obj)
|
481
|
+
{
|
482
|
+
VALUE v_bandno;
|
483
|
+
int bandno;
|
484
|
+
GetImg(obj, data, im);
|
485
|
+
OutImg(obj, new, data_new, im_new);
|
486
|
+
|
487
|
+
rb_scan_args(argc, argv, "01", &v_bandno);
|
488
|
+
bandno = NIL_P(v_bandno) ? -1 : NUM2INT(v_bandno);
|
489
|
+
|
490
|
+
if (im_heq(im, im_new, bandno))
|
491
|
+
vips_lib_error();
|
492
|
+
|
493
|
+
return new;
|
494
|
+
}
|
495
|
+
|
496
|
+
/*
|
497
|
+
* call-seq:
|
498
|
+
* im.lhisteq(xwin, ywin) -> image
|
499
|
+
*
|
500
|
+
* Performs local histogram equalisation on *self* using a window of size
|
501
|
+
* <i>xwin</i> by <i>ywin</i> centered on the input pixel. Works only on
|
502
|
+
* monochrome images.
|
503
|
+
*
|
504
|
+
* The output image is the same size as the input image. The edge pixels are
|
505
|
+
* created by copy edge pixels of the input image outwards.
|
506
|
+
*/
|
507
|
+
|
508
|
+
VALUE
|
509
|
+
img_lhisteq(VALUE obj, VALUE xwin, VALUE ywin)
|
510
|
+
{
|
511
|
+
GetImg(obj, data, im);
|
512
|
+
OutImg(obj, new, data_new, im_new);
|
513
|
+
|
514
|
+
if (im_lhisteq(im, im_new, NUM2INT(xwin), NUM2INT(ywin)))
|
515
|
+
vips_lib_error();
|
516
|
+
|
517
|
+
return new;
|
518
|
+
}
|
519
|
+
|
520
|
+
/*
|
521
|
+
* call-seq:
|
522
|
+
* im.stdif(a, m0, b, s, xwin, ywin) -> image
|
523
|
+
*
|
524
|
+
* Preforms statistical differencing according to the formula given in page 45
|
525
|
+
* of the book "An Introduction to Digital Image Processing" by Wayne Niblack.
|
526
|
+
* This transformation emphasises the way in which a pel differs statistically
|
527
|
+
* from its neighbours. It is useful for enhancing low-contrast images with
|
528
|
+
* lots of detail, such as X-ray plates.
|
529
|
+
*
|
530
|
+
* At point (i,j) the output is given by the equation:
|
531
|
+
*
|
532
|
+
* vout(i,j) = a * m0 + (1 - a) * meanv +
|
533
|
+
* (vin(i,j) - meanv) * (b * s0) / (s0 + b * stdv)
|
534
|
+
*
|
535
|
+
* Values <i>a</i>, <i>m0</i>, <i>b</i> and <i>s0</i> are entered, while meanv
|
536
|
+
* and stdv are the values calculated over a moving window of size <i>xwin</i>,
|
537
|
+
* <i>ywin</i> centred on pixel (i,j).
|
538
|
+
*
|
539
|
+
* <i>m0</i> is the new mean, <i>a</i> is the weight given to it. <i>s0</i> is
|
540
|
+
* the new standard deviation, <i>b</i> is the weight given to it.
|
541
|
+
*
|
542
|
+
* Try:
|
543
|
+
*
|
544
|
+
* im.stdif(0.5, 128, 0.5, 50, 11, 11)
|
545
|
+
*
|
546
|
+
* The operation works on one-band uchar images only, and writes a one-band
|
547
|
+
* uchar image as its result. The output image has the same size as the
|
548
|
+
* input.
|
549
|
+
*/
|
550
|
+
|
551
|
+
VALUE
|
552
|
+
img_stdif(VALUE obj,
|
553
|
+
VALUE a, VALUE m0, VALUE b, VALUE s0, VALUE xwin, VALUE ywin)
|
554
|
+
{
|
555
|
+
GetImg(obj, data, im);
|
556
|
+
OutImg(obj, new, data_new, im_new);
|
557
|
+
|
558
|
+
if (im_stdif(im, im_new,
|
559
|
+
NUM2DBL(a), NUM2DBL(m0), NUM2DBL(b), NUM2DBL(s0),
|
560
|
+
NUM2INT(xwin), NUM2INT(ywin)))
|
561
|
+
vips_lib_error();
|
562
|
+
|
563
|
+
return new;
|
564
|
+
}
|
565
|
+
|
566
|
+
/*
|
567
|
+
* call-seq:
|
568
|
+
* Image.tone_build_range(in_max, out_max, lb, lw, ps, pm, ph, s, m, h) -> image
|
569
|
+
*
|
570
|
+
* Generates a tone curve for the adjustment of image levels. It is mostly
|
571
|
+
* designed for adjusting the L* part of a LAB image in way suitable for print
|
572
|
+
* work, but you can use it for other things too.
|
573
|
+
*
|
574
|
+
* The curve is an unsigned 16-bit image with (<i>in_max</i> + 1) entries, each
|
575
|
+
* in the range [0, <i>out_max</i>].
|
576
|
+
*
|
577
|
+
* <i>lb</i>, <i>lw</i> are expressed as 0-100, as in LAB colour space. You
|
578
|
+
* specify the scaling for the input and output images with the <i>in_max</i>
|
579
|
+
* and <i>out_max</i> parameters.
|
580
|
+
*/
|
581
|
+
|
582
|
+
VALUE
|
583
|
+
img_s_tone_build_range(VALUE obj,
|
584
|
+
VALUE in_max, VALUE out_max,
|
585
|
+
VALUE lb, VALUE lw, VALUE ps, VALUE pm, VALUE ph, VALUE s, VALUE m, VALUE h)
|
586
|
+
{
|
587
|
+
OutPartial(new, data, im);
|
588
|
+
|
589
|
+
if (im_tone_build_range(im,
|
590
|
+
NUM2DBL(in_max), NUM2DBL(out_max),
|
591
|
+
NUM2DBL(lb), NUM2DBL(lw), NUM2DBL(ps), NUM2DBL(pm), NUM2DBL(ph),
|
592
|
+
NUM2DBL(s), NUM2DBL(m), NUM2DBL(h)))
|
593
|
+
vips_lib_error();
|
594
|
+
|
595
|
+
return new;
|
596
|
+
}
|
597
|
+
|
598
|
+
/*
|
599
|
+
* call-seq:
|
600
|
+
* Image.tone_build(lb, lw, ps, pm, ph, s, m, h) -> image
|
601
|
+
*
|
602
|
+
* As Image#tone_build_range, but set 32767 and 32767 as values for
|
603
|
+
* <i>in_max</i> and <i>out_max</i>. This makes a curve suitable for correcting
|
604
|
+
* LABS images, the most common case.
|
605
|
+
*/
|
606
|
+
|
607
|
+
VALUE
|
608
|
+
img_s_tone_build(VALUE obj,
|
609
|
+
VALUE lb, VALUE lw, VALUE ps, VALUE pm, VALUE ph, VALUE s, VALUE m, VALUE h)
|
610
|
+
{
|
611
|
+
OutPartial(new, data, im);
|
612
|
+
|
613
|
+
if (im_tone_build(im,
|
614
|
+
NUM2DBL(lb), NUM2DBL(lw), NUM2DBL(ps), NUM2DBL(pm), NUM2DBL(ph),
|
615
|
+
NUM2DBL(s), NUM2DBL(m), NUM2DBL(h)))
|
616
|
+
vips_lib_error();
|
617
|
+
|
618
|
+
return new;
|
619
|
+
}
|
620
|
+
|
621
|
+
/*
|
622
|
+
* call-seq:
|
623
|
+
* im.tone_analyze(ps, pm, ph, s, m, h) -> image
|
624
|
+
*
|
625
|
+
* As Image#tone_build, but analyse the histogram of *self* and use it to pick
|
626
|
+
* the 0.1% and 99.9% points for <i>lb</i> and <i>lw</i>.
|
627
|
+
*/
|
628
|
+
|
629
|
+
VALUE
|
630
|
+
img_tone_analyze(VALUE obj,
|
631
|
+
VALUE ps, VALUE pm, VALUE ph, VALUE s, VALUE m, VALUE h)
|
632
|
+
{
|
633
|
+
#if IM_MAJOR_VERSION > 7 || IM_MINOR_VERSION >= 23
|
634
|
+
GetImg(obj, data, im);
|
635
|
+
OutImg(obj, new, data_new, im_new);
|
636
|
+
|
637
|
+
if (im_tone_analyze(im, im_new,
|
638
|
+
NUM2DBL(ps), NUM2DBL(pm), NUM2DBL(ph),
|
639
|
+
NUM2DBL(s), NUM2DBL(m), NUM2DBL(h)) )
|
640
|
+
vips_lib_error();
|
641
|
+
|
642
|
+
return new;
|
643
|
+
#else
|
644
|
+
rb_raise(eVIPSError, "This operation is not supported by your version of VIPS");
|
645
|
+
#endif
|
646
|
+
}
|