48 lines
831 B
Go
48 lines
831 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"golang.org/x/image/tiff"
|
|
"image"
|
|
"image/color"
|
|
_ "image/jpeg"
|
|
"os"
|
|
)
|
|
|
|
func convert(i image.Image) image.Image {
|
|
rect := i.Bounds()
|
|
n := image.NewGray(rect)
|
|
for x := 0; x < rect.Max.X; x++ {
|
|
for y := 0; y < rect.Max.Y; y++ {
|
|
p := color.GrayModel.Convert(i.At(x, y)).(color.Gray)
|
|
if p.Y <= 130 {
|
|
n.Set(x, y, p)
|
|
} else {
|
|
n.Set(x, y, color.White)
|
|
}
|
|
}
|
|
}
|
|
return n
|
|
}
|
|
|
|
func main() {
|
|
in, err := os.Open(os.Args[1])
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
out, err := os.OpenFile(os.Args[2], os.O_RDWR|os.O_CREATE, 0644)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
i, _, err := image.Decode(in)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
err = tiff.Encode(out, convert(i), &tiff.Options{tiff.Uncompressed, false})
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
}
|