@@ -209,12 +209,13 @@ public static bool ImagesAreEqual(Image<Rgb24> actual, Image<Rgb24> expected, Re
209
209
/// <param name="pathActualImage"></param>
210
210
/// <param name="pathExpectedImage"></param>
211
211
/// <param name="resizeOption"></param>
212
+ /// <param name="pixelColorShiftTolerance"></param>
212
213
/// <returns>Mean and absolute pixel error</returns>
213
- public static ICompareResult CalcDiff ( string pathActualImage , string pathExpectedImage , ResizeOption resizeOption = ResizeOption . DontResize )
214
+ public static ICompareResult CalcDiff ( string pathActualImage , string pathExpectedImage , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
214
215
{
215
216
using var actual = Image . Load ( pathActualImage ) ;
216
217
using var expected = Image . Load ( pathExpectedImage ) ;
217
- return CalcDiff ( actual , expected , resizeOption ) ;
218
+ return CalcDiff ( actual , expected , resizeOption , pixelColorShiftTolerance ) ;
218
219
}
219
220
220
221
/// <summary>
@@ -224,13 +225,14 @@ public static ICompareResult CalcDiff(string pathActualImage, string pathExpecte
224
225
/// <param name="pathExpectedImage"></param>
225
226
/// <param name="pathMaskImage"></param>
226
227
/// <param name="resizeOption"></param>
228
+ /// <param name="pixelColorShiftTolerance"></param>
227
229
/// <returns>Mean and absolute pixel error</returns>
228
- public static ICompareResult CalcDiff ( string pathActualImage , string pathExpectedImage , string pathMaskImage , ResizeOption resizeOption = ResizeOption . DontResize )
230
+ public static ICompareResult CalcDiff ( string pathActualImage , string pathExpectedImage , string pathMaskImage , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
229
231
{
230
232
using var actual = Image . Load ( pathActualImage ) ;
231
233
using var expected = Image . Load ( pathExpectedImage ) ;
232
234
using var mask = Image . Load ( pathMaskImage ) ;
233
- return CalcDiff ( actual , expected , mask , resizeOption ) ;
235
+ return CalcDiff ( actual , expected , mask , resizeOption , pixelColorShiftTolerance ) ;
234
236
}
235
237
236
238
/// <summary>
@@ -239,12 +241,13 @@ public static ICompareResult CalcDiff(string pathActualImage, string pathExpecte
239
241
/// <param name="actualImage"></param>
240
242
/// <param name="expectedImage"></param>
241
243
/// <param name="resizeOption"></param>
244
+ /// <param name="pixelColorShiftTolerance"></param>
242
245
/// <returns>Mean and absolute pixel error</returns>
243
- public static ICompareResult CalcDiff ( Stream actualImage , Stream expectedImage , ResizeOption resizeOption = ResizeOption . DontResize )
246
+ public static ICompareResult CalcDiff ( Stream actualImage , Stream expectedImage , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
244
247
{
245
248
using var actual = Image . Load ( actualImage ) ;
246
249
using var expected = Image . Load ( expectedImage ) ;
247
- return CalcDiff ( actual , expected , resizeOption ) ;
250
+ return CalcDiff ( actual , expected , resizeOption , pixelColorShiftTolerance ) ;
248
251
}
249
252
250
253
/// <summary>
@@ -254,12 +257,13 @@ public static ICompareResult CalcDiff(Stream actualImage, Stream expectedImage,
254
257
/// <param name="expectedImage"></param>
255
258
/// <param name="maskImage"></param>
256
259
/// <param name="resizeOption"></param>
260
+ /// <param name="pixelColorShiftTolerance"></param>
257
261
/// <returns></returns>
258
- public static ICompareResult CalcDiff ( Stream actualImage , Stream expectedImage , Image maskImage , ResizeOption resizeOption = ResizeOption . DontResize )
262
+ public static ICompareResult CalcDiff ( Stream actualImage , Stream expectedImage , Image maskImage , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
259
263
{
260
264
using var actual = Image . Load ( actualImage ) ;
261
265
using var expected = Image . Load ( expectedImage ) ;
262
- return CalcDiff ( actual , expected , maskImage , resizeOption ) ;
266
+ return CalcDiff ( actual , expected , maskImage , resizeOption , pixelColorShiftTolerance ) ;
263
267
}
264
268
265
269
/// <summary>
@@ -268,11 +272,11 @@ public static ICompareResult CalcDiff(Stream actualImage, Stream expectedImage,
268
272
/// <param name="actual"></param>
269
273
/// <param name="expected"></param>
270
274
/// <param name="resizeOption"></param>
275
+ /// <param name="pixelColorShiftTolerance"></param>
271
276
/// <returns>Mean and absolute pixel error</returns>
272
- public static ICompareResult CalcDiff ( Image actual , Image expected , ResizeOption resizeOption = ResizeOption . DontResize )
277
+ public static ICompareResult CalcDiff ( Image actual , Image expected , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
273
278
{
274
279
ArgumentNullException . ThrowIfNull ( actual ) ;
275
-
276
280
ArgumentNullException . ThrowIfNull ( expected ) ;
277
281
278
282
var ownsActual = false ;
@@ -285,7 +289,7 @@ public static ICompareResult CalcDiff(Image actual, Image expected, ResizeOption
285
289
actualRgb24 = ToRgb24Image ( actual , out ownsActual ) ;
286
290
expectedRgb24 = ToRgb24Image ( expected , out ownsExpected ) ;
287
291
288
- return CalcDiff ( actualRgb24 , expectedRgb24 , resizeOption ) ;
292
+ return CalcDiff ( actualRgb24 , expectedRgb24 , resizeOption , pixelColorShiftTolerance ) ;
289
293
}
290
294
finally
291
295
{
@@ -306,8 +310,9 @@ public static ICompareResult CalcDiff(Image actual, Image expected, ResizeOption
306
310
/// <param name="actual"></param>
307
311
/// <param name="expected"></param>
308
312
/// <param name="resizeOption"></param>
313
+ /// <param name="pixelColorShiftTolerance"></param>
309
314
/// <returns>Mean and absolute pixel error</returns>
310
- public static ICompareResult CalcDiff ( Image < Rgb24 > actual , Image < Rgb24 > expected , ResizeOption resizeOption = ResizeOption . DontResize )
315
+ public static ICompareResult CalcDiff ( Image < Rgb24 > actual , Image < Rgb24 > expected , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
311
316
{
312
317
var imagesHaveSameDimension = ImagesHaveSameDimension ( actual , expected ) ;
313
318
@@ -316,7 +321,7 @@ public static ICompareResult CalcDiff(Image<Rgb24> actual, Image<Rgb24> expected
316
321
var grown = GrowToSameDimension ( actual , expected ) ;
317
322
try
318
323
{
319
- return CalcDiff ( grown . Item1 , grown . Item2 , ResizeOption . DontResize ) ;
324
+ return CalcDiff ( grown . Item1 , grown . Item2 , ResizeOption . DontResize , pixelColorShiftTolerance ) ;
320
325
}
321
326
finally
322
327
{
@@ -344,9 +349,9 @@ public static ICompareResult CalcDiff(Image<Rgb24> actual, Image<Rgb24> expected
344
349
var r = Math . Abs ( expectedPixel . R - actualPixel . R ) ;
345
350
var g = Math . Abs ( expectedPixel . G - actualPixel . G ) ;
346
351
var b = Math . Abs ( expectedPixel . B - actualPixel . B ) ;
347
- absoluteError = absoluteError + r + g + b ;
348
-
349
- pixelErrorCount += r + g + b > 0 ? 1 : 0 ;
352
+ var sum = r + g + b ;
353
+ absoluteError = absoluteError + ( sum > pixelColorShiftTolerance ? sum : 0 ) ;
354
+ pixelErrorCount += ( sum > pixelColorShiftTolerance ) ? 1 : 0 ;
350
355
}
351
356
}
352
357
@@ -355,15 +360,18 @@ public static ICompareResult CalcDiff(Image<Rgb24> actual, Image<Rgb24> expected
355
360
return new CompareResult ( absoluteError , meanError , pixelErrorCount , pixelErrorPercentage ) ;
356
361
}
357
362
363
+
364
+
358
365
/// <summary>
359
366
/// Calculates ICompareResult expressing the amount of difference of both images using a image mask for tolerated difference between the two images
360
367
/// </summary>
361
368
/// <param name="actual"></param>
362
369
/// <param name="expected"></param>
363
370
/// <param name="maskImage"></param>
364
371
/// <param name="resizeOption"></param>
372
+ /// <param name="pixelColorShiftTolerance"></param>
365
373
/// <returns>Mean and absolute pixel error</returns>
366
- public static ICompareResult CalcDiff ( Image actual , Image expected , Image maskImage , ResizeOption resizeOption = ResizeOption . DontResize )
374
+ public static ICompareResult CalcDiff ( Image actual , Image expected , Image maskImage , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
367
375
{
368
376
ArgumentNullException . ThrowIfNull ( actual ) ;
369
377
@@ -410,8 +418,9 @@ public static ICompareResult CalcDiff(Image actual, Image expected, Image maskIm
410
418
/// <param name="expected"></param>
411
419
/// <param name="maskImage"></param>
412
420
/// <param name="resizeOption"></param>
421
+ /// <param name="pixelColorShiftTolerance"></param>
413
422
/// <returns>Mean and absolute pixel error</returns>
414
- public static ICompareResult CalcDiff ( Image < Rgb24 > actual , Image < Rgb24 > expected , Image < Rgb24 > maskImage , ResizeOption resizeOption = ResizeOption . DontResize )
423
+ public static ICompareResult CalcDiff ( Image < Rgb24 > actual , Image < Rgb24 > expected , Image < Rgb24 > maskImage , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
415
424
{
416
425
ArgumentNullException . ThrowIfNull ( maskImage ) ;
417
426
@@ -485,12 +494,13 @@ public static ICompareResult CalcDiff(Image<Rgb24> actual, Image<Rgb24> expected
485
494
/// <param name="pathActualImage"></param>
486
495
/// <param name="pathExpectedImage"></param>
487
496
/// <param name="resizeOption"></param>
497
+ /// <param name="pixelColorShiftTolerance"></param>
488
498
/// <returns>Image representing diff, black means no diff between actual image and expected image, white means max diff</returns>
489
- public static Image CalcDiffMaskImage ( string pathActualImage , string pathExpectedImage , ResizeOption resizeOption = ResizeOption . DontResize )
499
+ public static Image CalcDiffMaskImage ( string pathActualImage , string pathExpectedImage , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
490
500
{
491
501
using var actual = Image . Load ( pathActualImage ) ;
492
502
using var expected = Image . Load ( pathExpectedImage ) ;
493
- return CalcDiffMaskImage ( actual , expected , resizeOption ) ;
503
+ return CalcDiffMaskImage ( actual , expected , resizeOption , pixelColorShiftTolerance ) ;
494
504
}
495
505
496
506
/// <summary>
@@ -500,13 +510,14 @@ public static Image CalcDiffMaskImage(string pathActualImage, string pathExpecte
500
510
/// <param name="pathExpectedImage"></param>
501
511
/// <param name="pathMaskImage"></param>
502
512
/// <param name="resizeOption"></param>
513
+ /// <param name="pixelColorShiftTolerance"></param>
503
514
/// <returns>Image representing diff, black means no diff between actual image and expected image, white means max diff</returns>
504
- public static Image CalcDiffMaskImage ( string pathActualImage , string pathExpectedImage , string pathMaskImage , ResizeOption resizeOption = ResizeOption . DontResize )
515
+ public static Image CalcDiffMaskImage ( string pathActualImage , string pathExpectedImage , string pathMaskImage , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
505
516
{
506
517
using var actual = Image . Load ( pathActualImage ) ;
507
518
using var expected = Image . Load ( pathExpectedImage ) ;
508
519
using var mask = Image . Load ( pathMaskImage ) ;
509
- return CalcDiffMaskImage ( actual , expected , mask , resizeOption ) ;
520
+ return CalcDiffMaskImage ( actual , expected , mask , resizeOption , pixelColorShiftTolerance ) ;
510
521
}
511
522
512
523
/// <summary>
@@ -515,12 +526,13 @@ public static Image CalcDiffMaskImage(string pathActualImage, string pathExpecte
515
526
/// <param name="actualImage"></param>
516
527
/// <param name="expectedImage"></param>
517
528
/// <param name="resizeOption"></param>
529
+ /// <param name="pixelColorShiftTolerance"></param>
518
530
/// <returns>Image representing diff, black means no diff between actual image and expected image, white means max diff</returns>
519
- public static Image CalcDiffMaskImage ( Stream actualImage , Stream expectedImage , ResizeOption resizeOption = ResizeOption . DontResize )
531
+ public static Image CalcDiffMaskImage ( Stream actualImage , Stream expectedImage , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
520
532
{
521
533
using var actual = Image . Load ( actualImage ) ;
522
534
using var expected = Image . Load ( expectedImage ) ;
523
- return CalcDiffMaskImage ( actual , expected , resizeOption ) ;
535
+ return CalcDiffMaskImage ( actual , expected , resizeOption , pixelColorShiftTolerance ) ;
524
536
}
525
537
526
538
/// <summary>
@@ -530,13 +542,14 @@ public static Image CalcDiffMaskImage(Stream actualImage, Stream expectedImage,
530
542
/// <param name="expectedImage"></param>
531
543
/// <param name="maskImage"></param>
532
544
/// <param name="resizeOption"></param>
545
+ /// <param name="pixelColorShiftTolerance"></param>
533
546
/// <returns>Image representing diff, black means no diff between actual image and expected image, white means max diff</returns>
534
- public static Image CalcDiffMaskImage ( Stream actualImage , Stream expectedImage , Stream maskImage , ResizeOption resizeOption = ResizeOption . DontResize )
547
+ public static Image CalcDiffMaskImage ( Stream actualImage , Stream expectedImage , Stream maskImage , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
535
548
{
536
549
using var actual = Image . Load ( actualImage ) ;
537
550
using var expected = Image . Load ( expectedImage ) ;
538
551
using var mask = Image . Load ( maskImage ) ;
539
- return CalcDiffMaskImage ( actual , expected , mask , resizeOption ) ;
552
+ return CalcDiffMaskImage ( actual , expected , mask , resizeOption , pixelColorShiftTolerance ) ;
540
553
}
541
554
542
555
/// <summary>
@@ -545,8 +558,9 @@ public static Image CalcDiffMaskImage(Stream actualImage, Stream expectedImage,
545
558
/// <param name="actual"></param>
546
559
/// <param name="expected"></param>
547
560
/// <param name="resizeOption"></param>
561
+ /// <param name="pixelColorShiftTolerance"></param>
548
562
/// <returns>Image representing diff, black means no diff between actual image and expected image, white means max diff</returns>
549
- public static Image CalcDiffMaskImage ( Image actual , Image expected , ResizeOption resizeOption = ResizeOption . DontResize )
563
+ public static Image CalcDiffMaskImage ( Image actual , Image expected , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
550
564
{
551
565
ArgumentNullException . ThrowIfNull ( actual ) ;
552
566
@@ -562,7 +576,7 @@ public static Image CalcDiffMaskImage(Image actual, Image expected, ResizeOption
562
576
actualRgb24 = ToRgb24Image ( actual , out ownsActual ) ;
563
577
expectedRgb24 = ToRgb24Image ( expected , out ownsExpected ) ;
564
578
565
- return CalcDiffMaskImage ( actualRgb24 , expectedRgb24 , resizeOption ) ;
579
+ return CalcDiffMaskImage ( actualRgb24 , expectedRgb24 , resizeOption , pixelColorShiftTolerance ) ;
566
580
}
567
581
finally
568
582
{
@@ -584,8 +598,9 @@ public static Image CalcDiffMaskImage(Image actual, Image expected, ResizeOption
584
598
/// <param name="expected"></param>
585
599
/// <param name="mask"></param>
586
600
/// <param name="resizeOption"></param>
601
+ /// <param name="pixelColorShiftTolerance"></param>
587
602
/// <returns>Image representing diff, black means no diff between actual image and expected image, white means max diff</returns>
588
- public static Image CalcDiffMaskImage ( Image actual , Image expected , Image mask , ResizeOption resizeOption = ResizeOption . DontResize )
603
+ public static Image CalcDiffMaskImage ( Image actual , Image expected , Image mask , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
589
604
{
590
605
ArgumentNullException . ThrowIfNull ( actual ) ;
591
606
ArgumentNullException . ThrowIfNull ( expected ) ;
@@ -603,7 +618,7 @@ public static Image CalcDiffMaskImage(Image actual, Image expected, Image mask,
603
618
expectedRgb24 = ToRgb24Image ( expected , out ownsExpected ) ;
604
619
maskRgb24 = ToRgb24Image ( mask , out ownsMask ) ;
605
620
606
- return CalcDiffMaskImage ( actualRgb24 , expectedRgb24 , maskRgb24 , resizeOption ) ;
621
+ return CalcDiffMaskImage ( actualRgb24 , expectedRgb24 , maskRgb24 , resizeOption , pixelColorShiftTolerance ) ;
607
622
}
608
623
finally
609
624
{
@@ -628,8 +643,9 @@ public static Image CalcDiffMaskImage(Image actual, Image expected, Image mask,
628
643
/// <param name="actual"></param>
629
644
/// <param name="expected"></param>
630
645
/// <param name="resizeOption"></param>
646
+ /// <param name="pixelColorShiftTolerance"></param>
631
647
/// <returns>Image representing diff, black means no diff between actual image and expected image, white means max diff</returns>
632
- public static Image CalcDiffMaskImage ( Image < Rgb24 > actual , Image < Rgb24 > expected , ResizeOption resizeOption = ResizeOption . DontResize )
648
+ public static Image CalcDiffMaskImage ( Image < Rgb24 > actual , Image < Rgb24 > expected , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
633
649
{
634
650
var imagesHAveSameDimension = ImagesHaveSameDimension ( actual , expected ) ;
635
651
@@ -665,7 +681,7 @@ public static Image CalcDiffMaskImage(Image<Rgb24> actual, Image<Rgb24> expected
665
681
var grown = GrowToSameDimension ( actual , expected ) ;
666
682
try
667
683
{
668
- return CalcDiffMaskImage ( grown . Item1 , grown . Item2 , ResizeOption . DontResize ) ;
684
+ return CalcDiffMaskImage ( grown . Item1 , grown . Item2 , ResizeOption . DontResize , pixelColorShiftTolerance ) ;
669
685
}
670
686
finally
671
687
{
@@ -681,8 +697,9 @@ public static Image CalcDiffMaskImage(Image<Rgb24> actual, Image<Rgb24> expected
681
697
/// <param name="expected"></param>
682
698
/// <param name="mask"></param>
683
699
/// <param name="resizeOption"></param>
700
+ /// <param name="pixelColorShiftTolerance"></param>
684
701
/// <returns>Image representing diff, black means no diff between actual image and expected image, white means max diff</returns>
685
- public static Image CalcDiffMaskImage ( Image < Rgb24 > actual , Image < Rgb24 > expected , Image < Rgb24 > mask , ResizeOption resizeOption = ResizeOption . DontResize )
702
+ public static Image CalcDiffMaskImage ( Image < Rgb24 > actual , Image < Rgb24 > expected , Image < Rgb24 > mask , ResizeOption resizeOption = ResizeOption . DontResize , int pixelColorShiftTolerance = 0 )
686
703
{
687
704
ArgumentNullException . ThrowIfNull ( mask ) ;
688
705
var imagesHaveSameDimensions = ImagesHaveSameDimension ( actual , expected ) && ImagesHaveSameDimension ( actual , mask ) ;
@@ -719,7 +736,7 @@ public static Image CalcDiffMaskImage(Image<Rgb24> actual, Image<Rgb24> expected
719
736
var grown = GrowToSameDimension ( actual , expected , mask ) ;
720
737
try
721
738
{
722
- return CalcDiffMaskImage ( grown . Item1 , grown . Item2 , grown . Item3 , ResizeOption . DontResize ) ;
739
+ return CalcDiffMaskImage ( grown . Item1 , grown . Item2 , grown . Item3 , ResizeOption . DontResize , pixelColorShiftTolerance ) ;
723
740
}
724
741
finally
725
742
{
0 commit comments