public SignatureValidationResult ValidateSignature(Bitmap signedImage) { var tiles = signedImage.SplitIntoTiles(TileSize, TileSize); var signatureIsValid = true; var hammingCalculator = new HammingDistanceCalculator(); using (var graphics = Graphics.FromImage(signedImage)) { foreach (var tile in tiles) { using (tile) { var hash = CalculateSimpleHash(tile); var signature = _signatureEncoder.DecodeBits(tile.Bitmap); var hammingDistance = hammingCalculator.Calculate(hash, signature); if (hammingDistance > MaxHammingDistance) { signatureIsValid = false; DrawBorder(graphics, tile); } if (hammingDistance > 0) { DrawHammingDistance(graphics, tile, hammingDistance); } } } } return(new SignatureValidationResult() { ImageWithValidationMarks = signedImage, SignatureIsValid = signatureIsValid }); }
/// <summary> /// Compares two images and returns the Hamming distance. /// </summary> /// <param name="image1"></param> /// <param name="image2"></param> /// <returns>A value indicating whether the two images are similar or not.</returns> public CompareResult Compare(Image image1, Image image2) { if (image1 == null) { throw new ArgumentNullException(nameof(image1)); } if (image2 == null) { throw new ArgumentNullException(nameof(image2)); } if (image1.Width != image2.Width || image1.Height != image2.Height) { throw new ArgumentException("Images must have the same size"); } var PH = new KlingerDCTBasedPerceptualHasher(); IHash hash1 = PH.CalculateHash(image1); IHash hash2 = PH.CalculateHash(image2); HammingDistanceCalculator hdc = new HammingDistanceCalculator(hash1, hash2); var d = hdc.Distance; var inThreshold = hdc.CompareTo(threshold); return(new CompareResult() { Hash1 = hash1, Hash2 = hash2, Distance = new Distance(d), IntegerResult = inThreshold, Result = inThreshold <= 0 }); }
private ICodeGenerator CreateSUT() { var distanceCalculator = new HammingDistanceCalculator(); var variationsGenerator = new VariationsGenerator(); return(new CodeGenerator(variationsGenerator, distanceCalculator)); }
public void TestHammingDistance() { float expectedValue = 37; float result = HammingDistanceCalculator.CalculateDistance(Encoding.ASCII.GetBytes("this is a test"), Encoding.ASCII.GetBytes("wokka wokka!!!")); Assert.AreEqual(expectedValue, result); }
private Task <double> CalculatePerr(string text, Bitmap emptyContainer, int delta, double alpha) { return(Task.Factory.StartNew(() => { var kutter = new KutterEncoder(delta, alpha); var fullContainer = kutter.Encode(text, emptyContainer); var estimator = new HammingDistanceCalculator(); return estimator.EstimateBitErrorRate(text, fullContainer, kutter); })); }
private bool AllResultsHasMinimumDistance(IEnumerable <string> result, int distance) { var resultList = result.ToList(); var distanceCalculator = new HammingDistanceCalculator(); foreach (var item in resultList) { foreach (var otherItem in resultList) { if (otherItem != item) { if (distanceCalculator.GetDistance(item, otherItem) < distance) { return(false); } } } } return(true); }