-
Notifications
You must be signed in to change notification settings - Fork 0
/
png.go
35 lines (31 loc) · 663 Bytes
/
png.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
package main
import (
"fmt"
"image"
"image/png"
"os"
)
func ingestPng(fp string) []float64 {
file, err := os.Open(fp)
defer file.Close()
if err != nil {
fmt.Println("Error reading png", err)
}
img, err := png.Decode(file)
if err != nil {
fmt.Println("Error reading png 2", err)
}
bounds := img.Bounds()
grayScale := image.NewGray(bounds)
for x := 0; x < bounds.Max.X; x++ {
for y := 0; y < bounds.Max.Y; y++ {
pixel := img.At(x, y)
grayScale.Set(x, y, pixel)
}
}
pixelArray := make([]float64, len(grayScale.Pix))
for i, p := range grayScale.Pix {
pixelArray[i] = (float64(255-p) / 255.0 * 0.99) + 0.01
}
return pixelArray
}