| 79 | } |
| 80 | |
| 81 | func (s *ImageHashTestSuite) TestDCT2HashDifference() { |
| 82 | // Load original image hash |
| 83 | originalHash := s.calcHash("dct2/original.png", testutil.HashTypeDct) |
| 84 | |
| 85 | testCases := []struct { |
| 86 | filename string |
| 87 | expectedDistance float32 |
| 88 | }{ |
| 89 | {"dct2/brightness-minus1.png", 19.090097}, |
| 90 | {"dct2/brightness-minus10.png", 2008.260088}, |
| 91 | {"dct2/brightness-minus30.png", 19580.743012}, |
| 92 | {"dct2/brightness-minus50.png", 59795.423867}, |
| 93 | {"dct2/brightness-minus1-8bit.png", 35.761968}, |
| 94 | {"dct2/brightness-minus10-8bit.png", 2170.649351}, |
| 95 | {"dct2/brightness-minus30-8bit.png", 20112.324396}, |
| 96 | {"dct2/brightness-minus50-8bit.png", 60799.682862}, |
| 97 | {"dct2/jpeg-q99.jpg", 1.230422}, |
| 98 | {"dct2/jpeg-q80.jpg", 1.275000}, |
| 99 | {"dct2/jpeg-q60.jpg", 1.422987}, |
| 100 | {"dct2/jpeg-q40.jpg", 1.904982}, |
| 101 | {"dct2/jpeg-q20.jpg", 2.367389}, |
| 102 | {"dct2/jpeg-q1.jpg", 95.573785}, |
| 103 | {"dct2/hue-plus1.png", 50.101667}, |
| 104 | {"dct2/hue-plus10.png", 4834.754080}, |
| 105 | {"dct2/hue-plus50.png", 87091.950577}, |
| 106 | {"dct2/region-5x5-hue-plus1.png", 0.000002}, |
| 107 | {"dct2/region-5x5-hue-plus10.png", 0.000472}, |
| 108 | {"dct2/region-5x5-hue-plus50.png", 0.212683}, |
| 109 | {"dct2/region-10x10-hue-plus1.png", 0.000044}, |
| 110 | {"dct2/region-10x10-hue-plus10.png", 0.010890}, |
| 111 | {"dct2/region-10x10-hue-plus50.png", 3.514549}, |
| 112 | {"dct2/region-30x30-hue-plus1.png", 0.004835}, |
| 113 | {"dct2/region-30x30-hue-plus10.png", 0.782760}, |
| 114 | {"dct2/region-30x30-hue-plus50.png", 185.500887}, |
| 115 | {"dct2/region-50x50-hue-plus1.png", 0.035596}, |
| 116 | {"dct2/region-50x50-hue-plus10.png", 4.304423}, |
| 117 | {"dct2/region-50x50-hue-plus50.png", 840.811707}, |
| 118 | } |
| 119 | |
| 120 | for _, tc := range testCases { |
| 121 | s.Run(tc.filename, func() { |
| 122 | testHash := s.calcHash(tc.filename, testutil.HashTypeDct) |
| 123 | |
| 124 | distance, err := originalHash.Distance(testHash) |
| 125 | s.Require().NoError(err) |
| 126 | |
| 127 | // Allow 1% tolerance, with a minimum absolute delta of 0.001 |
| 128 | delta := tc.expectedDistance*0.01 + 0.001 |
| 129 | s.InDelta(tc.expectedDistance, distance, float64(delta), "unexpected distance") |
| 130 | }) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | func (s *ImageHashTestSuite) TestSHA256HashCalc() { |
| 135 | testCases := []struct { |