Tensorflow: DecodeJpeg method gives different pixel values on desktop and mobile for the same image
Asked Answered
R

1

11

I have used Tensorflow's DecodeJpeg to read images while training a model. In order to use the same method on an android device, I compiled Tensorflow with Bazel for android with DecodeJpeg.

I tried reading the same image on my desktop, which is an x86_64 machine that runs windows. I ran the DecodeJpeg method on an image with default values with dct_method set to '', INTEGER_FAST, INTEGER_ACCURATE.

I did the same on an arm64 device, for the same image. But, the pixel values were significantly different for the same image under the same settings.

For instance, at (100,100,1) the value on the desktop is 213, while it is 204 on arm64.

How can I make sure that the pixel values are the same across these two devices?[![This is the image I have used][1]][1]

Update: On Gimp at (100,100) the pixel values are (179,203,190)

For dct_method set to INTEGER_FAST, the value at (100,100) on x86_64 is (171, 213, 165), on arm it is (180, 204, 191)

For dct_method set to INTEGER_ACCURATE, the value at (100,100) on x86_64 is (170, 212, 164), on arm it is (179, 203, 190)

It is (170, 212, 164) with PIL, which is what I get with cv2.imread as well.

Romantic answered 10/4, 2018 at 8:29 Comment(0)
C
0

According to tensorflow image decode_jpeg documentation I expect that it may be relative to some attribute when you decode the jpeg. Most probably the channels attribute and/or the ratio attribute and/or the fancy_upscaling attr.

Both of them can change the value of the pixel...

Concerning the channels:

The attr channels indicate the desired number of color channels for the decoded image.

Accepted values are:

0: Use the number of channels in the JPEG-encoded image.
1: output a grayscale image.
3: output an RGB image.

Concerning the ratio:

The attr ratio allows downscaling the image by an integer factor during decoding. Allowed values are 1, 2, 4, and 8. This is much faster than downscaling the image later.

Concerning the fancy_upscaling:

fancy_upscaling: An optional bool. Defaults to True. If true use a slower but nicer upscaling of the chroma planes (yuv420/422 only).


Please note that you may also have to explicitly specify a value for the dct_method because according to documentation if you don't specify a value it will use a system-specific default.

And in my opinion, it (the dct_method empty arg) is the most probable reason which explains why you don't have the same result on x86_64 and ARM.

the internal jpeg library changes to a version that does not have that specific option

Chablis answered 27/4, 2018 at 10:52 Comment(1)
Please take a look at the update to the question. I have included values for different dct methods. On both x86_64 and arm, I'm using default values for ratio and fancy_upscaling, and channels is set to 3.Romantic

© 2022 - 2024 — McMap. All rights reserved.