I have a test jpeg I'm using for some image processing code & I'm trying to get the same array of uint8 values that opencv in python and C and Pillow (via scipy) in Python, which all match the values I get when I open the jpeg using gimp.
I tried shifting the color values 8 bits, but this does not convert the values accurately - it looks like there's some rounding that I don't quite understand. I know gimp and opencv and Pillow/scipy all use libjpeg, so I tried using https://github.com/pixiv/go-libjpeg and converting the images to 8 bits using
func Convert(img image.Image) *image.RGBA {
b := img.Bounds()
rgba := image.NewRGBA(b)
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
r32, g32, b32, _ := img.At(x, y).RGBA()
c := color.RGBA{uint8(r32>>8), uint8(g32>>8), uint8(b32>>8), 255}
rgba.SetRGBA(x, y, c)
}
}
return rgba
}
but this still does not match. How can I get the same results?