-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmosaicing.go
107 lines (83 loc) · 2.99 KB
/
mosaicing.go
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
package vips
/*
#cgo pkg-config: vips
#include "vips.h"
*/
import "C"
import (
"unsafe"
)
// Merge joins two images left-right (with ref on the left)
// or up-down (with ref above) with a smooth seam.
func (th *Image) Merge(sec *Image, direction Direction, dx, dy int) (err error) {
var vipsImage *C.VipsImage
if C.vipsimage_merge(th.vipsImage, sec.vipsImage, &vipsImage,
C.VipsDirection(direction), C.int(dx), C.int(dy)) != 0 {
return Error()
}
C.g_object_unref(C.gpointer(th.vipsImage))
th.vipsImage = vipsImage
return
}
// Mosaic joins two images left-right (with ref on the left)
// or top-bottom (with ref above) given an approximate overlap.
func (th *Image) Mosaic(sec *Image, direction Direction, xref, yref, xsec, ysec int) (err error) {
var vipsImage *C.VipsImage
if C.vipsimage_mosaic(th.vipsImage, sec.vipsImage, &vipsImage,
C.VipsDirection(direction), C.int(xref), C.int(yref), C.int(xsec), C.int(ysec)) != 0 {
return Error()
}
C.g_object_unref(C.gpointer(th.vipsImage))
th.vipsImage = vipsImage
return
}
// Mosaic1 This operation joins two images top-bottom (with sec on the right)
// or left-right (with sec at the bottom) given an approximate pair of tie-points.
// sec is scaled and rotated as necessary before the join.
func (th *Image) Mosaic1(sec *Image, direction Direction, xr1, yr1, xs1, ys1, xr2, yr2, xs2, ys2 int) (err error) {
var vipsImage *C.VipsImage
if C.vipsimage_mosaic1(th.vipsImage, sec.vipsImage, &vipsImage, C.VipsDirection(direction),
C.int(xr1), C.int(yr1), C.int(xs1), C.int(ys1), C.int(xr2), C.int(yr2), C.int(xs2), C.int(ys2)) != 0 {
return Error()
}
C.g_object_unref(C.gpointer(th.vipsImage))
th.vipsImage = vipsImage
return
}
// Match scale, rotate and translate sec so that the tie-points line up.
func (th *Image) Match(sec *Image, xr1, yr1, xs1, ys1, xr2, yr2, xs2, ys2 int) (err error) {
var vipsImage *C.VipsImage
if C.vipsimage_match(th.vipsImage, sec.vipsImage, &vipsImage,
C.int(xr1), C.int(yr1), C.int(xs1), C.int(ys1), C.int(xr2), C.int(yr2), C.int(xs2), C.int(ys2)) != 0 {
return Error()
}
C.g_object_unref(C.gpointer(th.vipsImage))
th.vipsImage = vipsImage
return
}
// GlobalBalance can be used to remove contrast differences in an assembled mosaic.
func (th *Image) GlobalBalance() (err error) {
var vipsImage *C.VipsImage
if C.vipsimage_globalbalance(th.vipsImage, &vipsImage) != 0 {
return Error()
}
C.g_object_unref(C.gpointer(th.vipsImage))
th.vipsImage = vipsImage
return
}
// ReMosaic takes apart the mosaiced image in and rebuilds it, substituting images.
// todo failed: class "remosaic" not found
func (th *Image) ReMosaic(oldStr, newStr string) (err error) {
var old *C.char = C.CString(oldStr)
defer C.free(unsafe.Pointer(old))
var nStr *C.char = C.CString(newStr)
defer C.free(unsafe.Pointer(nStr))
var vipsImage *C.VipsImage
if C.vipsimage_remosaic(th.vipsImage, &vipsImage,
old, nStr) != 0 {
return Error()
}
C.g_object_unref(C.gpointer(th.vipsImage))
th.vipsImage = vipsImage
return
}