-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ejercicio3.go
53 lines (46 loc) · 1.02 KB
/
Ejercicio3.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
package main
import (
"flag"
"fmt"
"image"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"log"
"os"
"time"
)
var infile = flag.String("infile", "img.png", "path to image (gif, jpeg, png)")
func main() {
flag.Parse()
reader, err := os.Open("01.jpg")
if err != nil {
log.Fatal(err)
}
defer reader.Close()
m, _, err := image.Decode(reader)
if err != nil {
log.Fatal(err)
}
bounds := m.Bounds()
var histogram [16][4]int
start := time.Now()
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
r, g, b, a := m.At(x, y).RGBA()
histogram[r>>12][0]++
histogram[g>>12][1]++
histogram[b>>12][2]++
histogram[a>>12][3]++
}
}
// Print the results.
fin := time.Since(start)
log.Printf("Ejercicio 3 Solución Normal")
log.Printf("Tiempo de ejecucion %s", fin)
fmt.Printf("%6s %6s %6s\n", "red", "green", "blue")
for i, x := range histogram {
fmt.Printf("%6d %6d %6d\n", x[0], x[1], x[2])
i = i + 1
}
}