private static FileEntry CalculateDiffImage(FileEntry oldImg, FileEntry newImg, double maxAllowedDiff, string errorMetric) { if (oldImg.Exists) { #if ENABLE_IMAGE_MAGICK using (ImageMagick.MagickImage original = new ImageMagick.MagickImage()) { original.LoadFromFileEntry(oldImg); ImageMagick.ErrorMetric eM = EnumUtil.Parse <ImageMagick.ErrorMetric>(errorMetric); var diff = original.Compare(newImg, eM, maxAllowedDiff); if (diff != null) { return(diff); } else { newImg.CopyToV2(oldImg, replaceExisting: true); } } #else Log.d("AssertVisually.AssertNoVisualChange() skipped: ENABLE_IMAGE_MAGICK define not active, see instructions 'readme Image Magick Unity Installation Instructions.txt'"); #endif } else { newImg.CopyToV2(oldImg, replaceExisting: false); } return(null); }
public static double Standardize( this ImageMagick.ErrorMetric errorMetric, double upperBound, double value, double transparencyRate = 0d) { const double STANDARD_UPPER_BOUND = 100d; // Would add PEAK_CROSS_POINT and such but it'd bloat the code. double result; switch (errorMetric) { case ImageMagick.ErrorMetric.PeakSignalToNoiseRatio: //result = value > 1d ? (double.IsPositiveInfinity(value) ? 1d : (1d - 1d / value) * 0.9375 + 0.0625) // : value * 0.0625; result = value > 1d ? (1d - 1d / value) * 0.9375 + 0.0625 : value * 0.0625; break; case ImageMagick.ErrorMetric.MeanErrorPerPixel: case ImageMagick.ErrorMetric.Absolute: result = value / upperBound; break; case ImageMagick.ErrorMetric.StructuralDissimilarity: result = value * 2; break; case ImageMagick.ErrorMetric.StructuralSimilarity: case ImageMagick.ErrorMetric.NormalizedCrossCorrelation: result = value; break; default: result = 1d - value; break; } if (transparencyRate > 0d) { if (transparencyRate < 1d) { result = (result - transparencyRate) / (1 - transparencyRate); } else { return(double.NaN); } } return(Math.Max(0d, Math.Min(STANDARD_UPPER_BOUND, result * STANDARD_UPPER_BOUND))); }
public static double UpperBound(this ImageMagick.ErrorMetric errorMetric, int pixelCount, int channels, int bitDepth = 255) { switch (errorMetric) { case ImageMagick.ErrorMetric.PeakSignalToNoiseRatio: return(double.PositiveInfinity); case ImageMagick.ErrorMetric.MeanErrorPerPixel: return(pixelCount * channels * bitDepth); case ImageMagick.ErrorMetric.Absolute: return(pixelCount); case ImageMagick.ErrorMetric.StructuralDissimilarity: return(0.5); default: return(1d); } }