Debian Codegraph @

convolution_test.go

raw symbols SCIP
1 package gift
2
3 import (
4 "image"
5 "testing"
6 )
7
8 func TestConvolution(t *testing.T) {
9 testData := []struct {
10 desc string
11 kernel []float32
12 normalize, alpha, abs bool
13 delta float32
14 srcb, dstb image.Rectangle
15 srcPix, dstPix []uint8
16 }{
17 {
18 "convolution (0x0, false, false, false, 0)",
19 []float32{},
20 false, false, false, 0,
21 image.Rect(-1, -1, 2, 2),
22 image.Rect(0, 0, 3, 3),
23 []uint8{
24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80,
25 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
26 0x80, 0x60, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
27 },
28 []uint8{
29 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80,
30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31 0x80, 0x60, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32 },
33 },
34 {
35 "convolution (3x3, false, false, false, 0)",
36 []float32{
37 0, 0, 1,
38 0, 0, 0,
39 1, 0, 0,
40 },
41 false, false, false, 0,
42 image.Rect(-1, -1, 2, 2),
43 image.Rect(0, 0, 3, 3),
44 []uint8{
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80,
46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47 0x80, 0x60, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48 },
49 []uint8{
50 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x00, 0x20, 0x40, 0x60, 0x80,
51 0x80, 0x60, 0x40, 0x00, 0xA0, 0xA0, 0xA0, 0x00, 0x20, 0x40, 0x60, 0x00,
52 0x80, 0x60, 0x40, 0x20, 0x80, 0x60, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
53 },
54 },
55 {
56 "convolution (3x3, true, false, false, 0)",
57 []float32{
58 0, 0, 1,
59 0, 0, 0,
60 1, 0, 0,
61 },
62 true, false, false, 0,
63 image.Rect(-1, -1, 2, 2),
64 image.Rect(0, 0, 3, 3),
65 []uint8{
66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80,
67 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68 0x80, 0x60, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
69 },
70 []uint8{
71 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x30, 0x00, 0x10, 0x20, 0x30, 0x80,
72 0x40, 0x30, 0x20, 0x00, 0x50, 0x50, 0x50, 0x00, 0x10, 0x20, 0x30, 0x00,
73 0x40, 0x30, 0x20, 0x20, 0x40, 0x30, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
74 },
75 },
76 {
77 "convolution (3x3, false, true, false, 0)",
78 []float32{
79 0, 0, 1,
80 0, 0, 0,
81 1, 0, 0,
82 },
83 false, true, false, 0,
84 image.Rect(-1, -1, 2, 2),
85 image.Rect(0, 0, 3, 3),
86 []uint8{
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80,
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89 0x80, 0x60, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90 },
91 []uint8{
92 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80, 0x20, 0x40, 0x60, 0x80,
93 0x80, 0x60, 0x40, 0x20, 0xA0, 0xA0, 0xA0, 0xA0, 0x20, 0x40, 0x60, 0x80,
94 0x80, 0x60, 0x40, 0x20, 0x80, 0x60, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00,
95 },
96 },
97 {
98 "convolution (3x3, true, true, true, 0)",
99 []float32{
100 0, 0, 0,
101 -0.5, 0, 0.5,
102 0, 0, 0,
103 },
104 true, true, true, 0,
105 image.Rect(-1, -1, 2, 2),
106 image.Rect(0, 0, 3, 3),
107 []uint8{
108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80,
109 0x80, 0x60, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80,
110 0x80, 0x60, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
111 },
112 []uint8{
113 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80, 0x20, 0x40, 0x60, 0x80,
114 0x80, 0x60, 0x40, 0x20, 0x60, 0x20, 0x20, 0x60, 0x20, 0x40, 0x60, 0x80,
115 0x80, 0x60, 0x40, 0x20, 0x80, 0x60, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00,
116 },
117 },
118 {
119 "convolution (3x3, false, true, false, 3 / 255.0)",
120 []float32{
121 0, 0, 1,
122 0, 0, 0,
123 1, 0, 0,
124 },
125 false, true, false, 3 / 255.0,
126 image.Rect(-1, -1, 2, 2),
127 image.Rect(0, 0, 3, 3),
128 []uint8{
129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80,
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131 0x80, 0x60, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 },
133 []uint8{
134 0x03, 0x03, 0x03, 0x03, 0x23, 0x43, 0x63, 0x83, 0x23, 0x43, 0x63, 0x83,
135 0x83, 0x63, 0x43, 0x23, 0xA3, 0xA3, 0xA3, 0xA3, 0x23, 0x43, 0x63, 0x83,
136 0x83, 0x63, 0x43, 0x23, 0x83, 0x63, 0x43, 0x23, 0x03, 0x03, 0x03, 0x03,
137 },
138 },
139 {
140 "convolution (3x3, false, false, true, 0)",
141 []float32{
142 0, 0, -0.5,
143 0, 0, 0,
144 0, 0, 0,
145 },
146 false, false, true, 0,
147 image.Rect(-1, -1, 2, 2),
148 image.Rect(0, 0, 3, 3),
149 []uint8{
150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80,
151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
152 0x80, 0x60, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
153 },
154 []uint8{
155 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x30, 0x00, 0x10, 0x20, 0x30, 0x80,
156 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x30, 0x00, 0x10, 0x20, 0x30, 0x00,
157 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
158 },
159 },
160 {
161 "convolution (7x7, false, true, false, 0)",
162 []float32{
163 0, 0, 0, 0, 0, 0, 1,
164 0, 0, 0, 0, 0, 0, 0,
165 0, 0, 0, 0, 0, 0, 0,
166 0, 0, 0, 0, 0, 0, 0,
167 0, 0, 0, 0, 0, 0, 0,
168 0, 0, 0, 0, 0, 0, 0,
169 1, 0, 0, 0, 0, 0, 0,
170 },
171 false, true, false, 0,
172 image.Rect(-1, -1, 2, 2),
173 image.Rect(0, 0, 3, 3),
174 []uint8{
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80,
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
177 0x80, 0x60, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
178 },
179 []uint8{
180 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0,
181 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0,
182 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0,
183 },
184 },
185 }
186
187 for _, d := range testData {
188 for _, workers := range []int{5, 1} {
189 src := image.NewNRGBA(d.srcb)
190 src.Pix = d.srcPix
191
192 f := Convolution(d.kernel, d.normalize, d.alpha, d.abs, d.delta)
193 dst := image.NewNRGBA(f.Bounds(src.Bounds()))
194 f.Draw(dst, src, &Options{Workers: workers})
195
196 if !checkBoundsAndPix(dst.Bounds(), d.dstb, dst.Pix, d.dstPix) {
197 t.Errorf("test [%s] failed: %#v, %#v", d.desc, dst.Bounds(), dst.Pix)
198 }
199 }
200 }
201
202 testKernelSizes := []struct {
203 klen, size int
204 }{
205 {0, 0},
206 {1, 1},
207 {3, 1},
208 {8, 1},
209 {9, 3},
210 {16, 3},
211 {24, 3},
212 {25, 5},
213 {40, 5},
214 {48, 5},
215 }
216
217 for _, d := range testKernelSizes {
218 tmp := make([]float32, d.klen)
219 sz, _ := prepareConvolutionWeights(tmp, true)
220 if sz != d.size {
221 t.Errorf("unexpected kernel size: %d %d", d.klen, sz)
222 }
223 }
224
225 // check no panics
226 Convolution([]float32{}, true, true, true, 1).Draw(image.NewGray(image.Rect(0, 0, 0, 0)), image.NewGray(image.Rect(0, 0, 0, 0)), nil)
227 convolve1dh(image.NewGray(image.Rect(0, 0, 1, 1)), image.NewGray(image.Rect(0, 0, 1, 1)), []float32{}, nil)
228 convolve1dv(image.NewGray(image.Rect(0, 0, 1, 1)), image.NewGray(image.Rect(0, 0, 1, 1)), []float32{}, nil)
229 convolve1dh(image.NewGray(image.Rect(0, 0, 0, 0)), image.NewGray(image.Rect(0, 0, 0, 0)), []float32{}, nil)
230 convolve1dv(image.NewGray(image.Rect(0, 0, 0, 0)), image.NewGray(image.Rect(0, 0, 0, 0)), []float32{}, nil)
231 convolveLine([]pixel{}, []pixel{}, []uweight{})
232 prepareConvolutionWeights1d([]float32{0, 0})
233 prepareConvolutionWeights1d([]float32{})
234 }
235
236 func TestGaussianBlur(t *testing.T) {
237 testData := []struct {
238 desc string
239 sigma float32
240 srcb, dstb image.Rectangle
241 srcPix, dstPix []uint8
242 }{
243 {
244 "blur (0)",
245 0,
246 image.Rect(-1, -1, 4, 2),
247 image.Rect(0, 0, 5, 3),
248 []uint8{
249 0x00, 0x00, 0x00, 0x00, 0x00,
250 0x00, 0xC0, 0x00, 0xC0, 0x00,
251 0x00, 0x00, 0x00, 0x00, 0x00,
252 },
253 []uint8{
254 0x00, 0x00, 0x00, 0x00, 0x00,
255 0x00, 0xC0, 0x00, 0xC0, 0x00,
256 0x00, 0x00, 0x00, 0x00, 0x00,
257 },
258 },
259 {
260 "blur (0.3)",
261 0.3,
262 image.Rect(-1, -1, 4, 2),
263 image.Rect(0, 0, 5, 3),
264 []uint8{
265 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x00, 0xC0, 0x00, 0xC0, 0x00,
267 0x00, 0x00, 0x00, 0x00, 0x00,
268 },
269 []uint8{
270 0x00, 0x01, 0x00, 0x01, 0x00,
271 0x01, 0xBD, 0x01, 0xBD, 0x01,
272 0x00, 0x01, 0x00, 0x01, 0x00,
273 },
274 },
275 {
276 "blur (1)",
277 1,
278 image.Rect(-1, -1, 4, 2),
279 image.Rect(0, 0, 5, 3),
280 []uint8{
281 0x00, 0x00, 0x00, 0x00, 0x00,
282 0x00, 0xC0, 0x00, 0xC0, 0x00,
283 0x00, 0x00, 0x00, 0x00, 0x00,
284 },
285 []uint8{
286 0x0B, 0x15, 0x16, 0x15, 0x0B,
287 0x13, 0x23, 0x25, 0x23, 0x13,
288 0x0B, 0x15, 0x16, 0x15, 0x0B,
289 },
290 },
291 {
292 "blur (3)",
293 3,
294 image.Rect(-1, -1, 4, 2),
295 image.Rect(0, 0, 5, 3),
296 []uint8{
297 0x00, 0x00, 0x00, 0x00, 0x00,
298 0x00, 0xC0, 0x00, 0xC0, 0x00,
299 0x00, 0x00, 0x00, 0x00, 0x00,
300 },
301 []uint8{
302 0x05, 0x06, 0x06, 0x06, 0x05,
303 0x05, 0x06, 0x06, 0x06, 0x05,
304 0x05, 0x06, 0x06, 0x06, 0x05,
305 },
306 },
307 }
308
309 for _, d := range testData {
310 src := image.NewGray(d.srcb)
311 src.Pix = d.srcPix
312
313 f := GaussianBlur(d.sigma)
314 dst := image.NewGray(f.Bounds(src.Bounds()))
315 f.Draw(dst, src, nil)
316
317 if !checkBoundsAndPix(dst.Bounds(), d.dstb, dst.Pix, d.dstPix) {
318 t.Errorf("test [%s] failed: %#v, %#v", d.desc, dst.Bounds(), dst.Pix)
319 }
320 }
321
322 // check no panics
323 GaussianBlur(0.5).Draw(image.NewGray(image.Rect(0, 0, 0, 0)), image.NewGray(image.Rect(0, 0, 0, 0)), nil)
324 }
325
326 func TestUnsharpMask(t *testing.T) {
327 testData := []struct {
328 desc string
329 sigma, amount, threshold float32
330 srcb, dstb image.Rectangle
331 srcPix, dstPix []uint8
332 }{
333 {
334 "unsharp mask (0.3, 1, 0)",
335 0.3, 1, 0,
336 image.Rect(-1, -1, 4, 2),
337 image.Rect(0, 0, 5, 3),
338 []uint8{
339 0x00, 0x40, 0x00, 0x40, 0x00,
340 0x60, 0xB0, 0xA0, 0xB0, 0x60,
341 0x00, 0x80, 0x00, 0x80, 0x00,
342 },
343 []uint8{
344 0x00, 0x40, 0x00, 0x40, 0x00,
345 0x60, 0xB1, 0xA1, 0xB1, 0x60,
346 0x00, 0x81, 0x00, 0x81, 0x00,
347 },
348 },
349 {
350 "unsharp mask (1, 1, 0)",
351 1, 1, 0,
352 image.Rect(-1, -1, 4, 2),
353 image.Rect(0, 0, 5, 3),
354 []uint8{
355 0x00, 0x40, 0x00, 0x40, 0x00,
356 0x60, 0xB0, 0xA0, 0xB0, 0x60,
357 0x00, 0x80, 0x00, 0x80, 0x00,
358 },
359 []uint8{
360 0x00, 0x45, 0x00, 0x45, 0x00,
361 0x82, 0xFF, 0xE4, 0xFF, 0x82,
362 0x00, 0xB2, 0x00, 0xB2, 0x00,
363 },
364 },
365 {
366 "unsharp mask (1, 0.5, 0)",
367 1, 0.5, 0,
368 image.Rect(-1, -1, 4, 2),
369 image.Rect(0, 0, 5, 3),
370 []uint8{
371 0x00, 0x40, 0x00, 0x40, 0x00,
372 0x60, 0xB0, 0xA0, 0xB0, 0x60,
373 0x00, 0x80, 0x00, 0x80, 0x00,
374 },
375 []uint8{
376 0x00, 0x42, 0x00, 0x42, 0x00,
377 0x71, 0xDD, 0xC2, 0xDD, 0x71,
378 0x00, 0x99, 0x00, 0x99, 0x00,
379 },
380 },
381 {
382 "unsharp mask (1, 1, 0.05)",
383 1, 1, 0.05,
384 image.Rect(-1, -1, 4, 2),
385 image.Rect(0, 0, 5, 3),
386 []uint8{
387 0x00, 0x40, 0x00, 0x40, 0x00,
388 0x60, 0xB0, 0xA0, 0xB0, 0x60,
389 0x00, 0x80, 0x00, 0x80, 0x00,
390 },
391 []uint8{
392 0x00, 0x40, 0x00, 0x40, 0x00,
393 0x82, 0xFF, 0xE4, 0xFF, 0x82,
394 0x00, 0xB2, 0x00, 0xB2, 0x00,
395 },
396 },
397 }
398
399 for _, d := range testData {
400 src := image.NewGray(d.srcb)
401 src.Pix = d.srcPix
402
403 f := UnsharpMask(d.sigma, d.amount, d.threshold)
404 dst := image.NewGray(f.Bounds(src.Bounds()))
405 f.Draw(dst, src, nil)
406
407 if !checkBoundsAndPix(dst.Bounds(), d.dstb, dst.Pix, d.dstPix) {
408 t.Errorf("test [%s] failed: %#v, %#v", d.desc, dst.Bounds(), dst.Pix)
409 }
410 }
411
412 // check no panics
413 UnsharpMask(0.5, 1, 0).Draw(image.NewGray(image.Rect(0, 0, 0, 0)), image.NewGray(image.Rect(0, 0, 0, 0)), nil)
414 }
415
416 func TestMean(t *testing.T) {
417 testData := []struct {
418 desc string
419 ksize int
420 disk bool
421 srcb, dstb image.Rectangle
422 srcPix, dstPix []uint8
423 }{
424 {
425 "mean (0x0 false)",
426 0, false,
427 image.Rect(-1, -1, 4, 2),
428 image.Rect(0, 0, 5, 3),
429 []uint8{
430 0x00, 0x40, 0x00, 0x40, 0x00,
431 0x60, 0xB0, 0xA0, 0xB0, 0x60,
432 0x00, 0x80, 0x00, 0x80, 0x00,
433 },
434 []uint8{
435 0x00, 0x40, 0x00, 0x40, 0x00,
436 0x60, 0xB0, 0xA0, 0xB0, 0x60,
437 0x00, 0x80, 0x00, 0x80, 0x00,
438 },
439 },
440 {
441 "mean (1x1 false)",
442 1, false,
443 image.Rect(-1, -1, 4, 2),
444 image.Rect(0, 0, 5, 3),
445 []uint8{
446 0x00, 0x40, 0x00, 0x40, 0x00,
447 0x60, 0xB0, 0xA0, 0xB0, 0x60,
448 0x00, 0x80, 0x00, 0x80, 0x00,
449 },
450 []uint8{
451 0x00, 0x40, 0x00, 0x40, 0x00,
452 0x60, 0xB0, 0xA0, 0xB0, 0x60,
453 0x00, 0x80, 0x00, 0x80, 0x00,
454 },
455 },
456 {
457 "mean (2x2 true)",
458 2, true,
459 image.Rect(-1, -1, 4, 2),
460 image.Rect(0, 0, 5, 3),
461 []uint8{
462 0x00, 0x40, 0x00, 0x40, 0x00,
463 0x60, 0xB0, 0xA0, 0xB0, 0x60,
464 0x00, 0x80, 0x00, 0x80, 0x00,
465 },
466 []uint8{
467 0x00, 0x40, 0x00, 0x40, 0x00,
468 0x60, 0xB0, 0xA0, 0xB0, 0x60,
469 0x00, 0x80, 0x00, 0x80, 0x00,
470 },
471 },
472 {
473 "mean (3x3 false)",
474 3, false,
475 image.Rect(-1, -1, 4, 2),
476 image.Rect(0, 0, 5, 3),
477 []uint8{
478 0x10, 0x40, 0x00, 0x40, 0x10,
479 0x20, 0x50, 0x00, 0x50, 0x20,
480 0x30, 0x60, 0x00, 0x60, 0x30,
481 },
482 []uint8{
483 0x25, 0x1E, 0x2E, 0x1E, 0x25,
484 0x30, 0x25, 0x35, 0x25, 0x30,
485 0x3B, 0x2C, 0x3C, 0x2C, 0x3B,
486 },
487 },
488 {
489 "mean (3x3 true)",
490 3, true,
491 image.Rect(-1, -1, 4, 2),
492 image.Rect(0, 0, 5, 3),
493 []uint8{
494 0x10, 0x40, 0x00, 0x40, 0x10,
495 0x20, 0x50, 0x00, 0x50, 0x20,
496 0x30, 0x60, 0x00, 0x60, 0x30,
497 },
498 []uint8{
499 0x1D, 0x2D, 0x1A, 0x2D, 0x1D,
500 0x2A, 0x36, 0x20, 0x36, 0x2A,
501 0x36, 0x40, 0x26, 0x40, 0x36,
502 },
503 },
504 }
505
506 for _, d := range testData {
507 src := image.NewGray(d.srcb)
508 src.Pix = d.srcPix
509
510 f := Mean(d.ksize, d.disk)
511 dst := image.NewGray(f.Bounds(src.Bounds()))
512 f.Draw(dst, src, nil)
513
514 if !checkBoundsAndPix(dst.Bounds(), d.dstb, dst.Pix, d.dstPix) {
515 t.Errorf("test [%s] failed: %#v, %#v", d.desc, dst.Bounds(), dst.Pix)
516 }
517 }
518
519 // check no panics
520 Mean(5, false).Draw(image.NewGray(image.Rect(0, 0, 0, 0)), image.NewGray(image.Rect(0, 0, 0, 0)), nil)
521 }
522
523 func TestSobel(t *testing.T) {
524 testData := []struct {
525 desc string
526 srcb, dstb image.Rectangle
527 srcPix, dstPix []uint8
528 }{
529 {
530 "sobel 0x0",
531 image.Rect(0, 0, 0, 0),
532 image.Rect(0, 0, 0, 0),
533 []uint8{},
534 []uint8{},
535 },
536 {
537 "sobel 6x6",
538 image.Rect(-1, -1, 5, 5),
539 image.Rect(0, 0, 6, 6),
540 []uint8{
541 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
542 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
543 0x00, 0x00, 0x99, 0x99, 0x99, 0x99,
544 0x00, 0x00, 0x99, 0x99, 0x99, 0x99,
545 0x00, 0x00, 0x99, 0x99, 0x99, 0x99,
546 0x00, 0x00, 0x99, 0x99, 0x99, 0x99,
547 },
548 []uint8{
549 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
550 0x00, 0xd8, 0xff, 0xff, 0xff, 0xff,
551 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
552 0x00, 0xff, 0xff, 0x00, 0x00, 0x00,
553 0x00, 0xff, 0xff, 0x00, 0x00, 0x00,
554 0x00, 0xff, 0xff, 0x00, 0x00, 0x00,
555 },
556 },
557 }
558
559 for _, d := range testData {
560 src := image.NewGray(d.srcb)
561 src.Pix = d.srcPix
562
563 f := Sobel()
564 dst := image.NewGray(f.Bounds(src.Bounds()))
565 f.Draw(dst, src, nil)
566
567 if !checkBoundsAndPix(dst.Bounds(), d.dstb, dst.Pix, d.dstPix) {
568 t.Errorf("test [%s] failed: %#v, %#v", d.desc, dst.Bounds(), dst.Pix)
569 }
570 }
571 }