-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
62 lines (51 loc) · 1.39 KB
/
main.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
package main
import (
"fmt"
"image"
"image/jpeg"
"os"
"time"
"github.com/mdouchement/bilateral"
"github.com/mdouchement/bilateral/luminance"
)
var (
entries = []map[string]string{
{"type": "rgb", "name": "greekdome-gray", "in": "./greekdome-gray.jpeg", "out": "./greekdome-gray-filtered.jpeg"},
{"type": "rgb", "name": "greekdome-rgb", "in": "./greekdome.jpeg", "out": "./greekdome-filtered.jpeg"},
{"type": "lum", "name": "greekdome-gray-lum", "in": "./greekdome-gray.jpeg", "out": "./greekdome-gray-filtered-lum.jpeg"},
{"type": "lum", "name": "greekdome-rgb-lum", "in": "./greekdome.jpeg", "out": "./greekdome-filtered-lum.jpeg"},
}
)
func main() {
for _, entry := range entries {
fi, err := os.Open(entry["in"])
check(err)
defer fi.Close()
m, _, err := image.Decode(fi)
check(err)
fmt.Println(entry["name"], " bounds:", m.Bounds().Dx(), m.Bounds().Dy())
var m2 image.Image
start := time.Now()
if entry["type"] == "lum" {
fbl := luminance.Auto(m)
fbl.Execute()
m2 = fbl.ResultImage()
} else {
fbl := bilateral.Auto(m)
fbl.Execute()
m2 = fbl.ResultImage()
}
fmt.Printf("%s takes %v\n", entry["name"], time.Now().Sub(start))
fo, err := os.Create(entry["out"])
check(err)
defer fo.Close()
err = jpeg.Encode(fo, m2, &jpeg.Options{Quality: 100})
check(err)
fmt.Println("----")
}
}
func check(err error) {
if err != nil {
panic(err)
}
}