Jump to content

Percentage difference between images: Difference between revisions

→‎{{header|C#}}: GetPixel is an expensive call, optimized to minimize calls (Code is now 2.8x faster by BenchmarkDotNet test). Also optimized to remove repeated floating point rounding errors. .Net's Math.Abs is optimized, repeated calls can be left.
(→‎{{header|Perl}}: added an alternative solution using the Imager library)
(→‎{{header|C#}}: GetPixel is an expensive call, optimized to minimize calls (Code is now 2.8x faster by BenchmarkDotNet test). Also optimized to remove repeated floating point rounding errors. .Net's Math.Abs is optimized, repeated calls can be left.)
Line 337:
for (int x = 0; x < img1.Width; x++)
{
diffColor pixel1 += (float)Math.Abs(img1.GetPixel(x, y).R - img2.GetPixel(x, y).R) / 255;
diffColor pixel2 += (float)Math.Abs(img1.GetPixel(x, y).G - img2.GetPixel(x, y).G) / 255;
 
diff += (float)Math.Abs(img1.GetPixel(x, y).B - img2.GetPixel(x, y).B) / 255;
diff += Math.Abs(pixel1.R - pixel2.R);
diff += Math.Abs(pixel1.G - pixel2.G);
diff += (float)Math.Abs(img1.GetPixel(x, y)pixel1.B - img2.GetPixel(x, y)pixel2.B) / 255;
}
}
 
Console.WriteLine("diff: {0} %", 100 * (diff / 255) / (img1.Width * img1.Height * 3));
}
}</lang>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.