I'm trying to create a heat map from eye-tracker results (showing where on the screen was the user looking most frequently).
For pixels that the user looked frequently onto, I want to set non-transparent red color, for a bit less-frequent orange color, etc.. I'm using red to green color-scale. But for the pixels with the least frequency, I want them to not only show green color, I want them to be transparent.
imgfile, err := os.Open("unchanged.jpeg")
defer imgfile.Close()
if err != nil {
fmt.Println(err.Error())
}
decodedImg, err := jpeg.Decode(imgfile)
img := image.NewRGBA(decodedImg.Bounds())
size := img.Bounds().Size()
for x := 0; x < size.X; x++ {
for y := 0; y < size.Y; y++ {
img.Set(x, y, decodedImg.At(x, y))
}
}
// I change some pixels here with img.Set(...)
outFile, _ := os.Create("changed.png")
defer outFile.Close()
png.Encode(outFile, img)
The problem is that when I try to change color for example with img.Set(x, y, color.RGBA{85, 165, 34, 50})
it doesn't actually color the pixel as averaged value depending on old and new color, it just shows some new, strange-looking color.
Image with alpha RGBA value set to 50: (transparent)
Image with alpha RGBA value set to 255: (opaque)
I'm using png image that as far as I know does support transparency. Why does this happen? Any ideas that can solve this problem and make the least-frequently seen pixels appear transparent?
Thanks for every answer.