-
Notifications
You must be signed in to change notification settings - Fork 44
/
process.go
230 lines (178 loc) · 4.68 KB
/
process.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
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
package imgo
import (
"errors"
)
//input a image matrix as src , return a image matrix by sunseteffect process
func SunsetEffect(src [][][]uint8) [][][]uint8 {
height := len(src)
width := len(src[0])
imgMatrix := NewRGBAMatrix(height,width)
copy(imgMatrix,src)
for i:=0;i<height;i++{
for j:=0;j<width;j++{
imgMatrix[i][j][1] = uint8( float64(imgMatrix[i][j][1]) * 0.7 )
imgMatrix[i][j][2] = uint8( float64(imgMatrix[i][j][2]) * 0.7 )
}
}
return imgMatrix
}
// input a image as src , return a image matrix by negativefilmeffect process
func NegativeFilmEffect(src [][][]uint8) [][][]uint8 {
height := len(src)
width := len(src[0])
imgMatrix := NewRGBAMatrix(height,width)
copy(imgMatrix,src)
for i:=0;i<height;i++{
for j:=0;j<width;j++{
imgMatrix[i][j][0] = 255 - imgMatrix[i][j][0]
imgMatrix[i][j][1] = 255 - imgMatrix[i][j][1]
imgMatrix[i][j][2] = 255 - imgMatrix[i][j][2]
}
}
return imgMatrix
}
func Rotate(src [][][]uint8) [][][]uint8 {
height := len(src)
width := len(src[0])
imgMatrix := NewRGBAMatrix(width,height)
for i:=0;i<width;i++{
for j:=0;j<height;j++{
imgMatrix[i][j] = src[j][i]
}
}
return imgMatrix
}
func AdjustBrightness(src [][][]uint8 , light float64)(imgMatrix [][][]uint8 , err error) {
if light <= 0{
err = errors.New("value of light must be more than 0")
return
}
height := len(src)
width := len(src[0])
imgMatrix = NewRGBAMatrix(height,width)
copy(imgMatrix,src)
for i:=0;i<height;i++{
for j:=0;j<width;j++{
imgMatrix[i][j][0] = uint8(float64(imgMatrix[i][j][0])*light)
imgMatrix[i][j][1] = uint8(float64(imgMatrix[i][j][1])*light)
imgMatrix[i][j][2] = uint8(float64(imgMatrix[i][j][2])*light)
}
}
return
}
// fuse two images(filepath) and the size of new image is as src1
func ImageFusion(src1 string , src2 string)(imgMatrix [][][]uint8 , err error) {
imgMatrix1,err1 := Read(src1)
if err1 != nil {
err = err1
return
}
height:=len(imgMatrix1)
width:=len(imgMatrix1[0])
imgMatrix2,err2 := ResizeForMatrix(src2,width,height)
if err2 != nil {
err = err2
return
}
for i:=0;i<height;i++{
for j:=0;j<width;j++{
imgMatrix1[i][j][0] = uint8(float64(imgMatrix1[i][j][0])*0.5)+uint8(float64(imgMatrix2[i][j][0])*0.5)
imgMatrix1[i][j][1] = uint8(float64(imgMatrix1[i][j][1])*0.5)+uint8(float64(imgMatrix2[i][j][1])*0.5)
imgMatrix1[i][j][2] = uint8(float64(imgMatrix1[i][j][2])*0.5)+uint8(float64(imgMatrix1[i][j][2])*0.5)
}
}
imgMatrix = imgMatrix1
return
}
func VerticalMirror(src [][][]uint8) [][][]uint8 {
height := len(src)
width := len(src[0])
newwidth:=width*2
imgMatrix:=NewRGBAMatrix(height,newwidth)
for i:=0;i<height;i++{
for j:=0;j<width;j++{
imgMatrix[i][j] = src[i][j]
}
}
for i:=0;i<height;i++{
for j:=width;j<newwidth;j++{
imgMatrix[i][j] = imgMatrix[i][newwidth-j-1]
}
}
return imgMatrix
}
func HorizontalMirror(src [][][]uint8) [][][]uint8 {
height:=len(src)
width:=len(src[0])
newheight:=height*2
imgMatrix:=NewRGBAMatrix(newheight,width)
for i:=0;i<height;i++{
for j:=0;j<width;j++{
imgMatrix[i][j] = src[i][j]
}
}
for i:=height;i<newheight;i++{
for j:=0;j<width;j++{
imgMatrix[i][j] = imgMatrix[newheight-i-1][j]
}
}
return imgMatrix
}
func VerticalMirrorPart(src [][][]uint8) [][][]uint8 {
height := len(src)
width := len(src[0])
imgMatrix := NewRGBAMatrix(height,width)
copy(imgMatrix,src)
mirror_w:=width/2
for i:=0;i<height;i++{
for j:=0;j<mirror_w;j++{
imgMatrix[i][j] = imgMatrix[i][width-j-1]
}
}
return imgMatrix
}
//make a mirror of src
func HorizontalMirrorPart(src [][][]uint8) [][][]uint8 {
height := len(src)
width := len(src[0])
imgMatrix := NewRGBAMatrix(height,width)
copy(imgMatrix,src)
mirror_h:=height/2
for i:=0;i<mirror_h;i++{
for j:=0;j<width;j++{
imgMatrix[height-i-1][j] = imgMatrix[i][j]
}
}
return imgMatrix
}
func RGB2Gray(src [][][]uint8) [][][]uint8 {
height := len(src)
width := len(src[0])
imgMatrix := NewRGBAMatrix(height,width)
copy(imgMatrix,src)
for i:=0;i<height;i++{
for j:=0;j<width;j++{
avg:=(imgMatrix[i][j][0]+imgMatrix[i][j][1]+imgMatrix[i][j][3])/3
imgMatrix[i][j][0] = avg
imgMatrix[i][j][1] = avg
imgMatrix[i][j][2] = avg
}
}
return imgMatrix
}
// set the opacity of image matrix , opacity must be 0.0 to 1.0
func SetOpacity(src [][][]uint8, opacity float64)(imgMatrix [][][]uint8 , err error){
height := len(src)
width := len(src[0])
imgMatrix = NewRGBAMatrix(height,width)
copy(imgMatrix,src)
if opacity < 0.0 || opacity > 1.0 {
err = errors.New("the opacity is illegal!")
}
for i:=0;i<height;i++{
for j:=0;j<width;j++{
imgMatrix[i][j][3] = uint8(float64(imgMatrix[i][j][3])*opacity)
}
}
return
}