-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate.go
More file actions
425 lines (332 loc) · 11.6 KB
/
Copy pathcreate.go
File metadata and controls
425 lines (332 loc) · 11.6 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
package vips
/*
#cgo pkg-config: vips
#include "vips.h"
*/
import "C"
import (
"unsafe"
)
// Black make a black unsigned char image of a specified size.
func Black(width, height int) (out *Image, err error) {
out = New()
if C.vipsimage_black(&out.vipsImage, C.int(width), C.int(height)) != 0 {
err = Error()
return
}
return
}
// Xyz Create a two-band uint32 image where the elements in the
// first band have the value of their x coordinate and elements
// in the second band have their y coordinate.
//
// You can make any image where the value of a pixel is a function
// of its (x, y) coordinate by combining this operator with the
// arithmetic operators.
func Xyz(width, height int) (out *Image, err error) {
out = New()
if C.vipsimage_xyz(&out.vipsImage, C.int(width), C.int(height)) != 0 {
err = Error()
return
}
return
}
// Grey create a one-band float image with the left-most
// column zero and the right-most 1. Intermediate pixels
// are a linear ramp.
func Grey(width, height int) (out *Image, err error) {
out = New()
if C.vipsimage_grey(&out.vipsImage, C.int(width), C.int(height)) != 0 {
err = Error()
return
}
return
}
// GaussMat Creates a circularly symmetric Gaussian image of radius sigma.
// The size of the mask is determined by the variable minAmpl ;
// if for instance the value .1 is entered this means that the produced mask
// is clipped at values less than 10 percent of the maximum amplitude.
func GaussMat(sigma, minAmpl float64) (out *Image, err error) {
out = New()
if C.vipsimage_gaussmat(&out.vipsImage, C.double(sigma), C.double(minAmpl)) != 0 {
err = Error()
return
}
return
}
// LogMat creates a circularly symmetric Laplacian of Gaussian mask of radius sigma.
// The size of the mask is determined by the variable min_ampl ; if for instance the
// value .1 is entered this means that the produced mask is clipped at values within
// 10 persent of zero, and where the change between mask elements is less than 10%.
func LogMat(sigma, minAmpl float64) (out *Image, err error) {
out = New()
if C.vipsimage_logmat(&out.vipsImage, C.double(sigma), C.double(minAmpl)) != 0 {
err = Error()
return
}
return
}
// Text draw the string text to an image.
// out is a one-band 8-bit unsigned char image,
// with 0 for no text and 255 for text.
// Values between are used for anti-aliasing.
func Text(text string) (out *Image, err error) {
var txt *C.char = C.CString(text)
defer C.free(unsafe.Pointer(txt))
out = New()
if C.vipsimage_text(&out.vipsImage, txt) != 0 {
err = Error()
return
}
return
}
// GaussNoise make a one band float image of gaussian noise with the specified distribution.
// The noise distribution is created by averaging 12 random numbers with the appropriate weights.
func GaussNoise(width, height int) (out *Image, err error) {
out = New()
if C.vipsimage_gaussnoise(&out.vipsImage, C.int(width), C.int(height)) != 0 {
err = Error()
return
}
return
}
// Eye create a test pattern with increasing spatial frequence in X and amplitude in Y.
func Eye(width, height int) (out *Image, err error) {
out = New()
if C.vipsimage_eye(&out.vipsImage, C.int(width), C.int(height)) != 0 {
err = Error()
return
}
return
}
// Sines creates a float one band image of the a sine waveform in two dimensions.
func Sines(width, height int) (out *Image, err error) {
out = New()
if C.vipsimage_sines(&out.vipsImage, C.int(width), C.int(height)) != 0 {
err = Error()
return
}
return
}
// Zone create a one-band image of a zone plate.
func Zone(width, height int) (out *Image, err error) {
out = New()
if C.vipsimage_zone(&out.vipsImage, C.int(width), C.int(height)) != 0 {
err = Error()
return
}
return
}
// Identity creates an identity lookup table.
// ie. one which will leave an image unchanged when applied with Maplut().
// Each entry in the table has a value equal to its position.
func Identity() (out *Image, err error) {
out = New()
if C.vipsimage_identity(&out.vipsImage) != 0 {
err = Error()
return
}
return
}
// BuildLut this operation builds a lookup table from a set of points.
// Intermediate values are generated by piecewise linear interpolation
func (th *Image) BuildLut() (err error) {
var vipsImage *C.VipsImage
if C.vipsimage_buildlut(th.vipsImage, &vipsImage) != 0 {
return Error()
}
C.g_object_unref(C.gpointer(th.vipsImage))
th.vipsImage = vipsImage
return
}
// InvertLut given a mask of target values and real values, generate a
// LUT which will map reals to targets.
// Handy for linearising images from measurements of a colour chart.
// All values in [0,1]. Piecewise linear interpolation, extrapolate
// head and tail to 0 and 1.
func (th *Image) InvertLut() (err error) {
var vipsImage *C.VipsImage
if C.vipsimage_invertlut(th.vipsImage, &vipsImage) != 0 {
return Error()
}
C.g_object_unref(C.gpointer(th.vipsImage))
th.vipsImage = vipsImage
return
}
// ToneLut generates a tone curve for the adjustment of image levels.
// It is mostly designed for adjusting the L* part of a LAB image in
// a way suitable for print work, but you can use it for other things too.
func ToneLut() (out *Image, err error) {
out = New()
if C.vipsimage_tonelut(&out.vipsImage) != 0 {
err = Error()
return
}
return
}
// MaskIdeal Make an ideal high- or low-pass filter,
// that is, one with a sharp cutoff positioned at frequencyCutoff ,
// where frequencyCutoff is in the range 0 - 1.
func MaskIdeal(width, height int, frequencyCutoff float64) (out *Image, err error) {
out = New()
if C.vipsimage_mask_ideal(&out.vipsImage, C.int(width), C.int(height), C.double(frequencyCutoff)) != 0 {
err = Error()
return
}
return
}
// MaskIdealRing make an ideal ring-pass or ring-reject filter, that is, one with
// a sharp ring positioned at frequency_cutoff of width width , where frequencyCutoff
// and width are expressed as the range 0 - 1.
func MaskIdealRing(width, height int, frequencyCutoff, ringWidth float64) (out *Image, err error) {
out = New()
if C.vipsimage_mask_ideal_ring(&out.vipsImage,
C.int(width), C.int(height),
C.double(frequencyCutoff), C.double(ringWidth)) != 0 {
err = Error()
return
}
return
}
// MaskIdealBand make an ideal band-pass or band-reject filter,
// that is, one with a sharp cutoff around the point frequencyCutoffX,
// frequencyCutoffY of size radius .
func MaskIdealBand(width, height int, frequencyCutoffX, frequencyCutoffY, radius float64) (out *Image, err error) {
out = New()
if C.vipsimage_mask_ideal_band(&out.vipsImage,
C.int(width), C.int(height),
C.double(frequencyCutoffX), C.double(frequencyCutoffY), C.double(radius)) != 0 {
err = Error()
return
}
return
}
// MaskButterWorth make an butterworth high- or low-pass filter, that is, one with a variable,
// smooth transition positioned at frequency_cutoff , where frequency_cutoff is in range 0 - 1.
// The shape of the curve is controlled by order --- higher values give a sharper transition.
// See Gonzalez and Wintz, Digital Image Processing, 1987.
func MaskButterWorth(width, height int, order, frequencyCutoff, amplitudeCutoff float64) (out *Image, err error) {
out = New()
if C.vipsimage_mask_butterworth(&out.vipsImage,
C.int(width), C.int(height), C.double(order),
C.double(frequencyCutoff), C.double(amplitudeCutoff)) != 0 {
err = Error()
return
}
return
}
// MaskButterWorthRing Make a butterworth ring-pass or ring-reject filter,
// that is, one with a variable, smooth transition positioned at frequencyCutoff
// of width width , where frequencyCutoff is in the range 0 - 1. The shape of
// the curve is controlled by order --- higher values give a sharper transition.
// See Gonzalez and Wintz, Digital Image Processing, 1987.
func MaskButterWorthRing(width, height int, order, frequencyCutoff, amplitudeCutoff, ringWidth float64) (out *Image, err error) {
out = New()
if C.vipsimage_mask_butterworth_ring(&out.vipsImage,
C.int(width), C.int(height), C.double(order),
C.double(frequencyCutoff), C.double(amplitudeCutoff), C.double(ringWidth)) != 0 {
err = Error()
return
}
return
}
// MaskButterWorthBand make an butterworth band-pass or band-reject filter,
// that is, one with a variable, smooth transition positioned at frequencyCutoffX,
// frequencyCutoffY , of radius radius . The shape of the curve is controlled by
// order --- higher values give a sharper transition. See Gonzalez and Wintz,
// Digital Image Processing, 1987.
func MaskButterWorthBand(width, height int,
order, frequencyCutoffX, frequencyCutoffY, radius, amplitudeCutoff float64) (out *Image, err error) {
out = New()
if C.vipsimage_mask_butterworth_band(&out.vipsImage,
C.int(width), C.int(height), C.double(order),
C.double(frequencyCutoffX), C.double(frequencyCutoffY),
C.double(radius), C.double(amplitudeCutoff)) != 0 {
err = Error()
return
}
return
}
// MaskGaussian Make a gaussian high- or low-pass filter, that is, one with a variable,
// smooth transition positioned at frequencyCutoff .
func MaskGaussian(width, height int, frequencyCutoff, amplitudeCutoff float64) (out *Image, err error) {
out = New()
if C.vipsimage_mask_gaussian(&out.vipsImage,
C.int(width), C.int(height),
C.double(frequencyCutoff), C.double(amplitudeCutoff)) != 0 {
err = Error()
return
}
return
}
// MaskGaussianRing Make a gaussian ring-pass or ring-reject filter,
// that is, one with a variable, smooth transition positioned at
// frequencyCutoff of width ringWidth .
func MaskGaussianRing(width, height int, frequencyCutoff, amplitudeCutoff, ringWidth float64) (out *Image, err error) {
out = New()
if C.vipsimage_mask_gaussian_ring(&out.vipsImage,
C.int(width), C.int(height),
C.double(frequencyCutoff), C.double(amplitudeCutoff), C.double(ringWidth)) != 0 {
err = Error()
return
}
return
}
// MaskGaussianBand Make a gaussian band-pass or band-reject filter,
// that is, one with a variable, smooth transition positioned at
// frequencyCutoffX, frequencyCutoffY, of radius radius.
func MaskGaussianBand(width, height int, frequencyCutoffX, frequencyCutoffY, radius, amplitudeCutoff float64) (out *Image, err error) {
out = New()
if C.vipsimage_mask_gaussian_band(&out.vipsImage,
C.int(width), C.int(height),
C.double(frequencyCutoffX), C.double(frequencyCutoffY), C.double(radius),
C.double(amplitudeCutoff)) != 0 {
err = Error()
return
}
return
}
// MaskFractal operation should be used to create fractal images by
// filtering the power spectrum of Gaussian white noise. See GaussNoise().
func MaskFractal(width, height int, fractalDimension float64) (out *Image, err error) {
out = New()
if C.vipsimage_mask_fractal(&out.vipsImage, C.int(width), C.int(height), C.gdouble(fractalDimension)) != 0 {
err = Error()
return
}
return
}
// FractSurf Generate an image of size width by height and fractal dimension fractalDimension.
// The dimension should be between 2 and 3.
func FractSurf(width, height int, fractalDimension float64) (out *Image, err error) {
out = New()
if C.vipsimage_fractsurf(&out.vipsImage, C.int(width), C.int(height), C.double(fractalDimension)) != 0 {
err = Error()
return
}
return
}
// Worley create a one-band float image of Worley noise.
// See:
//
// https://en.wikipedia.org/wiki/Worley_noise
func Worley(width, height int) (out *Image, err error) {
out = New()
if C.vipsimage_worley(&out.vipsImage, C.int(width), C.int(height)) != 0 {
err = Error()
return
}
return
}
// Perlin create a one-band float image of Perlin noise.
// See:
//
// https://en.wikipedia.org/wiki/Perlin_noise
func Perlin(width, height int) (out *Image, err error) {
out = New()
if C.vipsimage_perlin(&out.vipsImage, C.int(width), C.int(height)) != 0 {
err = Error()
return
}
return
}