I'm no native English speaker, so please excuses any translation errors.
I'm not really having a coding problem. It's more of a conceptual question.
I wrote two times the same piece of code translating an image into a list of RGB values. (1 combination of 3 values for each pixel).
I wrote the code first in VB.net using:
Dim bmp As New Bitmap(File)
For x As Integer = 0 To w - 1
For y As Integer = 0 To h - 1
Dim c As Color = bmp.GetPixel(x, y)
Dim Red as integer = c.R
Dim Green as integer = c.G
Dim Blue as integer = c.B
Next y
next x
Afterwards I wrote the following in Java:
BufferedImage image = ImageIO.read(new File(File))
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
int pixel = image.getRGB(i,j);
int Red = ((pixel >> 16) & 0xff);
int Green = ((pixel >> 8) & 0xff);
int Blue = ((pixel) & 0xff);
}
}
My expectation would be to get the same values from both pieces of code, since they use the same image. I tried it on an image (270x320) which was a photograph (so a full spectrum of colors). To my surprise I saw there where small differences in the RGB values between the VB.net and Java codes.
If I compare the java(red)'s versus the VB.net(red)'s, the java(green)'s versus the VB.net(green)'s and the java(blue)'s versus the VB.net(blue)'s I compare 270x320x3 = 259.2k combinations. The differences between the integers gotten from the VB.net and from the Java code are as followed:
Can anybody explain to me where this difference comes from? Has it to do with the way of reading the colors, the way of buffering the image, or with something like anti-aliasing?
Really curious what the reason is, thx in advance
As mentioned by others, the difference is caused by JPEG's lossy compression.
You should be testing these methods with a lossless format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With