Last active
December 26, 2018 00:01
-
-
Save tenntenn/df953069f2fbcee02df3 to your computer and use it in GitHub Desktop.
Go言語でグレースケールの画像に変換 ref: https://qiita.com/tenntenn/items/0471e5f494df82c3e825
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"image" | |
"image/color" | |
"image/png" | |
"os" | |
) | |
func main() { | |
img, _ := png.Decode(os.Stdin) | |
bounds := img.Bounds() | |
dest := image.NewGray16(bounds) | |
for y := bounds.Min.Y; y < bounds.Max.Y; y++ { | |
for x := bounds.Min.X; x < bounds.Max.X; x++ { | |
c := color.Gray16Model.Convert(img.At(x, y)) | |
gray, _ := c.(color.Gray16) | |
dest.Set(x, y, gray) | |
} | |
} | |
png.Encode(os.Stdout, dest) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go run gray.go < gopher.png > gopher_gray.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment