Commit 38720a6b by samrobinson Committed by Marc Baechinger

Treat pixels as unsigned and correct pixel count division.

PiperOrigin-RevId: 451428202
parent 983e074f
...@@ -454,10 +454,10 @@ public final class SsimHelper { ...@@ -454,10 +454,10 @@ public final class SsimHelper {
double total = 0; double total = 0;
for (int y = 0; y < windowHeight; y++) { for (int y = 0; y < windowHeight; y++) {
for (int x = 0; x < windowWidth; x++) { 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. */ /** Calculates the variances and covariance of the pixels in the window for both buffers. */
...@@ -476,8 +476,8 @@ public final class SsimHelper { ...@@ -476,8 +476,8 @@ public final class SsimHelper {
for (int y = 0; y < windowHeight; y++) { for (int y = 0; y < windowHeight; y++) {
for (int x = 0; x < windowWidth; x++) { for (int x = 0; x < windowWidth; x++) {
int index = get1dIndex(x, y, stride, bufferIndexOffset); int index = get1dIndex(x, y, stride, bufferIndexOffset);
double referencePixelDeviation = referenceBuffer[index] - referenceMean; double referencePixelDeviation = (referenceBuffer[index] & 0xFF) - referenceMean;
double distortedPixelDeviation = distortedBuffer[index] - distortedMean; double distortedPixelDeviation = (distortedBuffer[index] & 0xFF) - distortedMean;
referenceVariance += referencePixelDeviation * referencePixelDeviation; referenceVariance += referencePixelDeviation * referencePixelDeviation;
distortedVariance += distortedPixelDeviation * distortedPixelDeviation; distortedVariance += distortedPixelDeviation * distortedPixelDeviation;
referenceDistortedCovariance += referencePixelDeviation * distortedPixelDeviation; referenceDistortedCovariance += referencePixelDeviation * distortedPixelDeviation;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment