JPEG图像有跨多个设备不同的像素值多个、像素、图像、不同

2023-09-07 03:13:41 作者:偏爱自由

我已经注意到,跨设备在相同的照片读取JPEG格式时,像素值不匹配。他们是接近,但不同的。当转换成PNG文件,像素值似乎匹配。

I had noticed that when reading in an identical photograph across devices in the JPEG format, the pixel values do not match up. They are close, but different. When converted to PNG files, the pixel values seem to match up.

这似乎,这将是由于跨设备(UN)的COM pression算法。这就是想到反正。有没有一种方法来读取JPEG文件,以便在同一像素从设备间的照片检索?我没有看到BitmapFactory选项组件中的一个选项。

This would seem that it would be due to the (un)compression algorithms across devices. That's what comes to mind anyways. Is there a way to read in JPEG files so that the same pixels are retrieved from the photograph across devices? I don't see an option within the BitmapFactory Options component.

目前应用在各种设备工作的图像时,像素值以下,以保持其大小:

Currently applying the following to maintain size when working on pixel values of an image across devices:

Options options = new Options();
options.inScaled = false;
options.inPreferQualityOverSpeed = true;

目前比较像素以下只是为了看几个(接近的比赛,但不等于):

Currently comparing pixels with the following just to look at a few (close matches, but not equal):

int[] pixels = new int[bitmapF.getWidth() * bitmapF.getHeight()];
bitmapF.getPixels(pixels, 0, bitmapF.getWidth(), 0, 0, bitmapF.getWidth(), bitmapF.getHeight());
Log.d("pixel entries", "pixels = " + pixels[233] + " - " + pixels[4002] + " - " + pixels[11391]);

注意:如果读同一文件,该文件是uncom pressed的PNG版本,该值如预期的一样

三星Galaxy S4例如与三星Galaxy S5甚至有来自同一个JPEG(流失相同的测试活动的)存储在资产文件夹不同的像素。

The Samsung Galaxy S4 for example and the Samsung Galaxy S5 even have different pixels from the same jpeg (running off of the same test activity) stored in the assets folder.

例如像素[233]将-5205635对S5但-5336451在S4。像素[4002]是一个小关为好。但是像素[11391]都是通过这两个装置相当于在此JPEG图片。

pixel[233] for instance would be -5205635 on s5 but -5336451 on the s4. The pixel[4002] is a little off as well. But pixel[11391] are equal across both devices on this jpeg picture.

推荐答案

JPEG标准并不要求去codeR实现生产位对位相同的输出图像。不幸的是,标准文档指定日codeR要求, ISO 10918-2 ,显然不是在线免费提供,但维基百科说:

The JPEG standard does not require that decoder implementations produce bit-for-bit identical output images. Unfortunately the standards document specifying decoder requirements, ISO 10918-2, is apparently not freely available online but Wikipedia says:

... JPEG标准(以及类似的MPEG标准)包括用于解码一些precision的要求,包括在解码过程的所有部分(可变长度解码,逆DCT,去量化,输出重正化);从参考算法的输出必须不超过:

...the JPEG standard (and the similar MPEG standards) includes some precision requirements for the decoding, including all parts of the decoding process (variable length decoding, inverse DCT, dequantization, renormalization of outputs); the output from the reference algorithm must not exceed:   最多1位差值的每个像素组件   在较低的均方误差在每一个8×8像素块    [等。]    a maximum 1 bit of difference for each pixel component low mean square error over each 8×8-pixel block [etc.]

使用相同的输入不同的去codeR输出之间的差别一般是由于不同的内部precision水平,特别是在执行IDCT。差异的另一个可能来源是平滑,它试图减少块效应的文物。

Differences between different decoder outputs using the same input are generally due to differing levels of internal precision, particularly in performing the IDCT. Another possible source of differences is smoothing, which attempts to reduce "blockiness" artifacts.

和你一样,我希望在preferQualityOverSpeed​​ 设置将产生相同的输出,但没有实际保证。我能想到的至少有一对夫妇的方式,你可以得到两个不同的手机小的变化:

Like you, I would expect that setting inPreferQualityOverSpeed would produce the same output but nothing actually guarantees that. I can think of at least a couple ways that you could get small variations on two different phones:

在该手机可以运行不同版本的Andr​​oid,其中 BitmapFactory 的实施改变(例如可能是在preferQualityOverSpeed​​ 被打破,然后固定,反之亦然),或 在该手机可以提供不同的硬件功能(如向量指令集,DSP协处理器等) BitmapFactory 利用。在标量浮点单元甚至差异可引起差异,特别是与JIT编译产生的实际的机器指令。 The phones may run different versions of Android where the implementation of BitmapFactory changed (e.g. perhaps inPreferQualityOverSpeed was broken and then fixed, or vice versa), or The phones may provide different hardware features (e.g. vector instruction set, DSP co-processor, etc.) that BitmapFactory leverages. Even differences in scalar floating-point units can cause discrepancies, especially with JIT compilation producing the actual machine instructions.

由于回旋余地标准中加上你的实验观察,它似乎保证位对位的协议,是在自己的应用程序进行解码的唯一途径。也许你可以找到一些替代的Andr​​oid兼容的库。

Given the wiggle room in the standard plus your experimental observations, it appears the only way to guarantee bit-for-bit agreement is to perform decoding within your own application. Perhaps you can find some alternative Android-compatible library.