///<summary> /// Returns the sum squared difference between this hash and the other hash. ///</summary> ///<param name="other">The ChannelPerceptualHash to get the distance of.</param> public double SumSquaredDistance(ChannelPerceptualHash other) { Throw.IfNull("other", other); double ssd = 0.0; for (int i = 0; i < 7; i++) { ssd += ((_SrgbHuPhash[i] - other._SrgbHuPhash[i]) * (_SrgbHuPhash[i] - other._SrgbHuPhash[i])); ssd += ((_HclpHuPhash[i] - other._HclpHuPhash[i]) * (_HclpHuPhash[i] - other._HclpHuPhash[i])); } return ssd; }
///<summary> /// Returns the sum squared difference between this hash and the other hash. ///</summary> ///<param name="other">The ChannelPerceptualHash to get the distance of.</param> public double SumSquaredDistance(ChannelPerceptualHash other) { Throw.IfNull("other", other); double ssd = 0.0; for (int i = 0; i < 7; i++) { ssd += ((_SrgbHuPhash[i] - other._SrgbHuPhash[i]) * (_SrgbHuPhash[i] - other._SrgbHuPhash[i])); ssd += ((_HclpHuPhash[i] - other._HclpHuPhash[i]) * (_HclpHuPhash[i] - other._HclpHuPhash[i])); } return(ssd); }
public void Test_Channel() { using (MagickImage image = new MagickImage(Files.ImageMagickJPG)) { PerceptualHash phash = image.PerceptualHash(); ChannelPerceptualHash channel = phash.GetChannel(PixelChannel.Red); ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate() { channel.HclpHuPhash(7); }); ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate() { channel.SrgbHuPhash(7); }); #if Q8 TestChannel(channel, 0, 0.6980, 0.6980, 0.0959, 0.0993); TestChannel(channel, 1, 3.4390, 3.4390, 0.6548, 0.6673); TestChannel(channel, 2, 3.9123, 3.9123, 0.9158, 0.9181); TestChannel(channel, 3, 4.2921, 4.2920, 2.3586, 2.3443); TestChannel(channel, 4, 8.7567, 8.7573, 4.8847, 4.9037); TestChannel(channel, 5, 8.2505, 8.2147, 2.8316, 2.8253); TestChannel(channel, 6, 8.4397, 8.4394, 3.9994, 3.9786); #elif Q16 TestChannel(channel, 0, 0.6979, 0.6979, 0.2578, 0.2574); TestChannel(channel, 1, 3.4385, 3.4385, 1.0557, 1.0505); TestChannel(channel, 2, 3.9123, 3.9123, 1.3807, 1.3839); TestChannel(channel, 3, 4.2920, 4.2920, 2.8467, 2.8534); TestChannel(channel, 4, 8.7555, 8.7555, 5.2023, 5.1805); TestChannel(channel, 5, 8.2995, 8.2995, 3.5194, 3.5081); TestChannel(channel, 6, 8.4397, 8.4397, 5.0468, 5.0770); #elif Q16HDRI TestChannel(channel, 0, 0.6979, 0.6979, 0.2927, 0.2932); TestChannel(channel, 1, 3.4385, 3.4385, 1.1754, 1.1742); TestChannel(channel, 2, 3.9123, 3.9123, 1.4998, 1.5044); TestChannel(channel, 3, 4.2920, 4.2920, 3.0736, 3.0744); TestChannel(channel, 4, 8.7556, 8.7555, 5.4465, 5.4449); TestChannel(channel, 5, 8.2997, 8.2994, 3.7136, 3.7108); TestChannel(channel, 6, 8.4398, 8.4397, 5.6025, 5.6170); #else #error Not implemented! #endif channel = phash.GetChannel(PixelChannel.Green); #if Q8 TestChannel(channel, 0, 0.6942, 0.6942, -0.0601, -0.0601); TestChannel(channel, 1, 3.3992, 3.3994, 0.3088, 0.3090); TestChannel(channel, 2, 4.1171, 4.1171, 0.6081, 0.6081); TestChannel(channel, 3, 4.4847, 4.4847, 0.7557, 0.7561); TestChannel(channel, 4, 8.8179, 8.8181, 1.7217, 1.7225); TestChannel(channel, 5, 6.4828, 6.4830, 0.9410, 0.9414); TestChannel(channel, 6, 9.2143, 9.2141, 1.5061, 1.5066); #elif Q16 TestChannel(channel, 0, 0.6942, 0.6942, -0.0601, -0.0601); TestChannel(channel, 1, 3.3988, 3.3988, 0.3089, 0.3089); TestChannel(channel, 2, 4.1168, 4.1168, 0.6083, 0.6083); TestChannel(channel, 3, 4.4844, 4.4844, 0.7555, 0.7555); TestChannel(channel, 4, 8.8174, 8.8174, 1.7219, 1.7219); TestChannel(channel, 5, 6.4821, 6.4821, 0.9408, 0.9408); TestChannel(channel, 6, 9.2147, 9.2147, 1.5058, 1.5058); #elif Q16HDRI TestChannel(channel, 0, 0.6942, 0.6942, -0.0601, -0.0601); TestChannel(channel, 1, 3.3988, 3.3988, 0.3089, 0.3089); TestChannel(channel, 2, 4.1168, 4.1168, 0.6083, 0.6083); TestChannel(channel, 3, 4.4844, 4.4844, 0.7555, 0.7555); TestChannel(channel, 4, 8.8174, 8.8174, 1.7219, 1.7219); TestChannel(channel, 5, 6.4821, 6.4821, 0.9408, 0.9408); TestChannel(channel, 6, 9.2148, 9.2147, 1.5058, 1.5058); #else #error Not implemented! #endif channel = phash.GetChannel(PixelChannel.Blue); #if Q8 TestChannel(channel, 0, 0.7223, 0.7223, 0.6984, 0.6984); TestChannel(channel, 1, 3.8298, 3.8298, 3.4611, 3.4611); TestChannel(channel, 2, 5.1307, 5.1306, 4.1312, 4.1311); TestChannel(channel, 3, 5.0216, 5.0218, 4.4867, 4.4867); TestChannel(channel, 4, 10.4775, 10.4768, 8.8669, 8.8668); TestChannel(channel, 5, 6.9452, 6.9454, 6.6106, 6.6108); TestChannel(channel, 6, 10.1394, 10.1398, 9.0727, 9.0722); #elif Q16 TestChannel(channel, 0, 0.7222, 0.7222, 0.6984, 0.6984); TestChannel(channel, 1, 3.8295, 3.8295, 3.4608, 3.4608); TestChannel(channel, 2, 5.1309, 5.1309, 4.1314, 4.1314); TestChannel(channel, 3, 5.0213, 5.0213, 4.4866, 4.4866); TestChannel(channel, 4, 10.4778, 10.4778, 8.8663, 8.8663); TestChannel(channel, 5, 6.9448, 6.9448, 6.6093, 6.6093); TestChannel(channel, 6, 10.1388, 10.1388, 9.0737, 9.0737); #elif Q16HDRI TestChannel(channel, 0, 0.7222, 0.7222, 0.6984, 0.6984); TestChannel(channel, 1, 3.8295, 3.8295, 3.4609, 3.4608); TestChannel(channel, 2, 5.1309, 5.1309, 4.1314, 4.1314); TestChannel(channel, 3, 5.0213, 5.0213, 4.4866, 4.4866); TestChannel(channel, 4, 10.4778, 10.4778, 8.8663, 8.8663); TestChannel(channel, 5, 6.9448, 6.9448, 6.6094, 6.6093); TestChannel(channel, 6, 10.1388, 10.1388, 9.0737, 9.0737); #else #error Not implemented! #endif } }
private void TestChannel(ChannelPerceptualHash channel, int index, double srgbHuPhashWithOpenCL, double srgbHuPhashWithoutOpenCL, double hclpHuPhashWithOpenCL, double hclpHuPhashWithoutOpenCL) { OpenCLValue.Assert(srgbHuPhashWithOpenCL, srgbHuPhashWithoutOpenCL, channel.SrgbHuPhash(index), 0.0001); OpenCLValue.Assert(hclpHuPhashWithOpenCL, hclpHuPhashWithoutOpenCL, channel.HclpHuPhash(index), 0.0001); }
public void Test_Channel() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { PerceptualHash phash = image.PerceptualHash(); ChannelPerceptualHash channel = phash.GetChannel(PixelChannel.Red); ExceptionAssert.Throws <ArgumentOutOfRangeException>(() => { channel.HclpHuPhash(7); }); ExceptionAssert.Throws <ArgumentOutOfRangeException>(() => { channel.SrgbHuPhash(7); }); #if Q8 TestChannel(channel, 0, 0.6980, 0.6980, 0.0974, 0.0993); TestChannel(channel, 1, 3.4388, 3.4390, 0.6582, 0.6685); TestChannel(channel, 2, 3.9123, 3.9123, 0.9238, 0.9195); TestChannel(channel, 3, 4.2922, 4.2920, 2.3627, 2.3354); TestChannel(channel, 4, 8.7570, 8.7574, 4.9574, 5.2273); TestChannel(channel, 5, 8.2422, 8.2149, 2.8422, 2.8360); TestChannel(channel, 6, 8.4397, 8.4394, 4.0087, 3.9636); #elif Q16 TestChannel(channel, 0, 0.6979, 0.6979, 0.2575, 0.2570); TestChannel(channel, 1, 3.4385, 3.4385, 1.0621, 1.0552); TestChannel(channel, 2, 3.9123, 3.9123, 1.3756, 1.3800); TestChannel(channel, 3, 4.2920, 4.2920, 2.8341, 2.8360); TestChannel(channel, 4, 8.7557, 8.7557, 5.1134, 5.1087); TestChannel(channel, 5, 8.3019, 8.3018, 3.4791, 3.4733); TestChannel(channel, 6, 8.4398, 8.4398, 5.0679, 5.0815); #elif Q16HDRI TestChannel(channel, 0, 0.6979, 0.6979, 0.2944, 0.2945); TestChannel(channel, 1, 3.4385, 3.4385, 1.1850, 1.1834); TestChannel(channel, 2, 3.9123, 3.9123, 1.5006, 1.5009); TestChannel(channel, 3, 4.2920, 4.2920, 3.0480, 3.0419); TestChannel(channel, 4, 8.7557, 8.7557, 5.3844, 5.3651); TestChannel(channel, 5, 8.3018, 8.3018, 3.6804, 3.6675); TestChannel(channel, 6, 8.4398, 8.4398, 5.6247, 5.6501); #else #error Not implemented! #endif channel = phash.GetChannel(PixelChannel.Green); #if Q8 TestChannel(channel, 0, 0.6942, 0.6942, -0.0601, -0.0601); TestChannel(channel, 1, 3.3993, 3.3995, 0.3090, 0.3093); TestChannel(channel, 2, 4.1171, 4.1172, 0.6084, 0.6083); TestChannel(channel, 3, 4.4847, 4.4847, 0.7559, 0.7566); TestChannel(channel, 4, 8.8180, 8.8183, 1.7224, 1.7237); TestChannel(channel, 5, 6.4829, 6.4832, 0.9413, 0.9421); TestChannel(channel, 6, 9.2143, 9.2141, 1.5065, 1.5074); #elif Q16 TestChannel(channel, 0, 0.6942, 0.6942, -0.0601, -0.0601); TestChannel(channel, 1, 3.3989, 3.3989, 0.3092, 0.3092); TestChannel(channel, 2, 4.1169, 4.1169, 0.6084, 0.6084); TestChannel(channel, 3, 4.4844, 4.4844, 0.7559, 0.7559); TestChannel(channel, 4, 8.8174, 8.8174, 1.7230, 1.7230); TestChannel(channel, 5, 6.4821, 6.4821, 0.9413, 0.9413); TestChannel(channel, 6, 9.2148, 9.2148, 1.5063, 1.5063); #elif Q16HDRI TestChannel(channel, 0, 0.6942, 0.6942, -0.0601, -0.0601); TestChannel(channel, 1, 3.3989, 3.3989, 0.3092, 0.3092); TestChannel(channel, 2, 4.1169, 4.1169, 0.6084, 0.6084); TestChannel(channel, 3, 4.4844, 4.4844, 0.7559, 0.7559); TestChannel(channel, 4, 8.8174, 8.8174, 1.7230, 1.7230); TestChannel(channel, 5, 6.4821, 6.4821, 0.9413, 0.9413); TestChannel(channel, 6, 9.2148, 9.2148, 1.5063, 1.5063); #else #error Not implemented! #endif channel = phash.GetChannel(PixelChannel.Blue); #if Q8 TestChannel(channel, 0, 0.7223, 0.7223, 0.6984, 0.6984); TestChannel(channel, 1, 3.8298, 3.8298, 3.4611, 3.4612); TestChannel(channel, 2, 5.1301, 5.1301, 4.1312, 4.1312); TestChannel(channel, 3, 5.0217, 5.0218, 4.4867, 4.4867); TestChannel(channel, 4, 10.4769, 10.4761, 8.8669, 8.8670); TestChannel(channel, 5, 6.9453, 6.9454, 6.6108, 6.6110); TestChannel(channel, 6, 10.1394, 10.1396, 9.0725, 9.0722); #elif Q16 TestChannel(channel, 0, 0.7222, 0.7222, 0.6984, 0.6984); TestChannel(channel, 1, 3.8295, 3.8295, 3.4609, 3.4609); TestChannel(channel, 2, 5.1304, 5.1304, 4.1314, 4.1314); TestChannel(channel, 3, 5.0214, 5.0214, 4.4866, 4.4866); TestChannel(channel, 4, 10.4771, 10.4772, 8.8663, 8.8663); TestChannel(channel, 5, 6.9448, 6.9448, 6.6094, 6.6094); TestChannel(channel, 6, 10.1388, 10.1388, 9.0737, 9.0737); #elif Q16HDRI TestChannel(channel, 0, 0.7222, 0.7222, 0.6984, 0.6984); TestChannel(channel, 1, 3.8295, 3.8295, 3.4609, 3.4609); TestChannel(channel, 2, 5.1304, 5.1304, 4.1314, 4.1314); TestChannel(channel, 3, 5.0214, 5.0214, 4.4866, 4.4866); TestChannel(channel, 4, 10.4772, 10.4772, 8.8663, 8.8663); TestChannel(channel, 5, 6.9448, 6.9448, 6.6094, 6.6094); TestChannel(channel, 6, 10.1388, 10.1388, 9.0737, 9.0737); #else #error Not implemented! #endif } }
public void Test_Channel() { #if NET20 Assert.Inconclusive("VS2008 compiler produces different results, no clue why this is happening"); #endif using (MagickImage image = new MagickImage(Files.ImageMagickJPG)) { PerceptualHash phash = image.PerceptualHash(); ChannelPerceptualHash channel = phash.GetChannel(PixelChannel.Red); ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate() { channel.HclpHuPhash(7); }); ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate() { channel.SrgbHuPhash(7); }); #if Q8 TestChannel(channel, 0, 0.6980, 0.0993); TestChannel(channel, 1, 3.4390, 0.6673); TestChannel(channel, 2, 3.9123, 0.9181); TestChannel(channel, 3, 4.2920, 2.3443); TestChannel(channel, 4, 8.7573, 4.9037); TestChannel(channel, 5, 8.2147, 2.8253); TestChannel(channel, 6, 8.4394, 3.9786); #elif Q16 TestChannel(channel, 0, 0.6979, 0.2574); TestChannel(channel, 1, 3.4385, 1.0505); TestChannel(channel, 2, 3.9123, 1.3839); TestChannel(channel, 3, 4.2920, 2.8534); TestChannel(channel, 4, 8.7555, 5.1805); TestChannel(channel, 5, 8.2995, 3.5081); TestChannel(channel, 6, 8.4397, 5.0770); #elif Q16HDRI TestChannel(channel, 0, 0.6979, 0.2932); TestChannel(channel, 1, 3.4385, 1.1742); TestChannel(channel, 2, 3.9123, 1.5044); TestChannel(channel, 3, 4.2920, 3.0744); TestChannel(channel, 4, 8.7555, 5.4449); TestChannel(channel, 5, 8.2994, 3.7108); TestChannel(channel, 6, 8.4397, 5.6170); #else #error Not implemented! #endif channel = phash.GetChannel(PixelChannel.Green); #if Q8 TestChannel(channel, 0, 0.6942, -0.06010); TestChannel(channel, 1, 3.3994, 0.30909); TestChannel(channel, 2, 4.1171, 0.60813); TestChannel(channel, 3, 4.4847, 0.75613); TestChannel(channel, 4, 8.8181, 1.72254); TestChannel(channel, 5, 6.4830, 0.94147); TestChannel(channel, 6, 9.2141, 1.50663); #elif Q16 TestChannel(channel, 0, 0.6942, -0.0601); TestChannel(channel, 1, 3.3988, 0.3089); TestChannel(channel, 2, 4.1168, 0.6083); TestChannel(channel, 3, 4.4844, 0.7555); TestChannel(channel, 4, 8.8174, 1.7219); TestChannel(channel, 5, 6.4821, 0.9408); TestChannel(channel, 6, 9.2147, 1.5058); #elif Q16HDRI TestChannel(channel, 0, 0.6942, -0.06014); TestChannel(channel, 1, 3.3988, 0.30899); TestChannel(channel, 2, 4.1168, 0.60836); TestChannel(channel, 3, 4.4844, 0.75556); TestChannel(channel, 4, 8.8174, 1.72197); TestChannel(channel, 5, 6.4821, 0.94082); TestChannel(channel, 6, 9.2147, 1.50582); #else #error Not implemented! #endif channel = phash.GetChannel(PixelChannel.Blue); #if Q8 TestChannel(channel, 0, 0.7223, 0.6984); TestChannel(channel, 1, 3.8298, 3.4611); TestChannel(channel, 2, 5.1306, 4.1311); TestChannel(channel, 3, 5.0218, 4.4867); TestChannel(channel, 4, 10.4768, 8.8668); TestChannel(channel, 5, 6.9454, 6.6108); TestChannel(channel, 6, 10.1398, 9.0722); #elif Q16 TestChannel(channel, 0, 0.7222, 0.6984); TestChannel(channel, 1, 3.8295, 3.4608); TestChannel(channel, 2, 5.1309, 4.1314); TestChannel(channel, 3, 5.0213, 4.4866); TestChannel(channel, 4, 10.4778, 8.8663); TestChannel(channel, 5, 6.9448, 6.6093); TestChannel(channel, 6, 10.1388, 9.0737); #elif Q16HDRI TestChannel(channel, 0, 0.7222, 0.6984); TestChannel(channel, 1, 3.8295, 3.4608); TestChannel(channel, 2, 5.1309, 4.1314); TestChannel(channel, 3, 5.0213, 4.4866); TestChannel(channel, 4, 10.4778, 8.8663); TestChannel(channel, 5, 6.9448, 6.6093); TestChannel(channel, 6, 10.1388, 9.0737); #else #error Not implemented! #endif } }
private void TestChannel(ChannelPerceptualHash channel, int index, double srgbHuPhash, double hclpHuPhash) { Assert.AreEqual(srgbHuPhash, channel.SrgbHuPhash(index), 0.0001); Assert.AreEqual(hclpHuPhash, channel.HclpHuPhash(index), 0.0001); }