Treat pixels as unsigned and correct pixel count division.

PiperOrigin-RevId: 451428202
This commit is contained in:
samrobinson 2022-05-27 17:40:45 +00:00 committed by Marc Baechinger
parent 67354cf2a7
commit a1b89561c1

View File

@ -454,10 +454,10 @@ public final class SsimHelper {
double total = 0;
for (int y = 0; y < windowHeight; y++) {
for (int x = 0; x < windowWidth; x++) {
total += pixelBuffer[get1dIndex(x, y, stride, bufferIndexOffset)];
total += pixelBuffer[get1dIndex(x, y, stride, bufferIndexOffset)] & 0xFF;
}
}
return total / windowWidth * windowHeight;
return total / (windowWidth * windowHeight);
}
/** Calculates the variances and covariance of the pixels in the window for both buffers. */
@ -476,8 +476,8 @@ public final class SsimHelper {
for (int y = 0; y < windowHeight; y++) {
for (int x = 0; x < windowWidth; x++) {
int index = get1dIndex(x, y, stride, bufferIndexOffset);
double referencePixelDeviation = referenceBuffer[index] - referenceMean;
double distortedPixelDeviation = distortedBuffer[index] - distortedMean;
double referencePixelDeviation = (referenceBuffer[index] & 0xFF) - referenceMean;
double distortedPixelDeviation = (distortedBuffer[index] & 0xFF) - distortedMean;
referenceVariance += referencePixelDeviation * referencePixelDeviation;
distortedVariance += distortedPixelDeviation * distortedPixelDeviation;
referenceDistortedCovariance += referencePixelDeviation * distortedPixelDeviation;