public void ComputeTest() { byte[,] gradient = new byte[255, 255]; for (int i = 0; i < 255; i++) for (int j = 0; j < 255; j++) gradient[i, j] = (byte)j; UnmanagedImage output; new MatrixToImage().Convert(gradient, out output); LocalBinaryPattern lbp = new LocalBinaryPattern(); List<double[]> result = lbp.ProcessImage(output); int[,] actualPatterns = lbp.Patterns; Assert.AreEqual(255, actualPatterns.GetLength(0)); Assert.AreEqual(255, actualPatterns.GetLength(1)); for (int i = 0; i < 255; i++) { for (int j = 0; j < 255; j++) { if (j == 0 || i == 0 || i == 254 || j == 254) { Assert.AreEqual(0, actualPatterns[i, j]); } else { Assert.AreEqual(7, actualPatterns[i, j]); } } } Assert.AreEqual(196, result.Count); }
public void CloneTest() { LocalBinaryPattern original = new LocalBinaryPattern(); LocalBinaryPattern target = (LocalBinaryPattern)original.Clone(); UnmanagedImage output = createGradient(); List <double[]> result = target.ProcessImage(output); int[,] actualPatterns = target.Patterns; Assert.AreEqual(255, actualPatterns.GetLength(0)); Assert.AreEqual(255, actualPatterns.GetLength(1)); for (int i = 0; i < 255; i++) { for (int j = 0; j < 255; j++) { if (j == 0 || i == 0 || i == 254 || j == 254) { Assert.AreEqual(0, actualPatterns[i, j]); } else { Assert.AreEqual(7, actualPatterns[i, j]); } } } Assert.AreEqual(196, result.Count); }
public void ComputeTest() { byte[,] gradient = new byte[255, 255]; for (int i = 0; i < 255; i++) { for (int j = 0; j < 255; j++) { gradient[i, j] = (byte)j; } } UnmanagedImage output; new MatrixToImage().Convert(gradient, out output); LocalBinaryPattern lbp = new LocalBinaryPattern(); List <double[]> result = lbp.ProcessImage(output); int[,] actualPatterns = lbp.Patterns; Assert.AreEqual(255, actualPatterns.GetLength(0)); Assert.AreEqual(255, actualPatterns.GetLength(1)); for (int i = 0; i < 255; i++) { for (int j = 0; j < 255; j++) { if (j == 0 || i == 0 || i == 254 || j == 254) { Assert.AreEqual(0, actualPatterns[i, j]); } else { Assert.AreEqual(7, actualPatterns[i, j]); } } } Assert.AreEqual(196, result.Count); }
public void doc_test() { string localPath = TestContext.CurrentContext.TestDirectory; #region doc_apply // Let's load an example image, such as Lena, // from a standard dataset of example images: var images = new TestImages(path: localPath); Bitmap lena = images["lena.bmp"]; // Create a new Local Binary Pattern with default values: var lbp = new LocalBinaryPattern(blockSize: 3, cellSize: 6); // Use it to extract descriptors from the Lena image: List <double[]> descriptors = lbp.ProcessImage(lena); // Now those descriptors can be used to represent the image itself, such // as for example, in the Bag-of-Visual-Words approach for classification. #endregion Assert.AreEqual(784, descriptors.Count); double sum = descriptors.Sum(x => x.Sum()); Assert.AreEqual(6094.543992693033, sum, 1e-10); }
public void bulkkprocess() { string[] file = Directory.GetFiles(@"C:\Users\kishor\Desktop\New folder (5)\cat\New folder", "*.png"); string orgImagePath = @"C:\Users\kishor\Desktop\New folder (5)\cat\17_cat.png";// file[0]; Bitmap lena = (Bitmap)Accord.Imaging.Image.FromFile(orgImagePath); // Create a new Local Binary Pattern with default values: var lbp = new LocalBinaryPattern(blockSize: 3, cellSize: 6); // Use it to extract descriptors from the Lena image: List <double[]> descriptors = lbp.ProcessImage(lena); var a = lbp.Histograms; // System.Console.Write("\n" + descriptors.Count+" v "); for (int i = 0; i < file.Length; i++) { var lbp2 = new LocalBinaryPattern(blockSize: 3, cellSize: 6); System.Console.Write("\"" + file[i] + "\""); string dupImagePath = file[i]; Bitmap lena2 = (Bitmap)Accord.Imaging.Image.FromFile(dupImagePath); List <double[]> descriptors2 = lbp2.ProcessImage(lena2); lena2.Dispose(); var b = lbp2.Histograms; // var percentage = getAbsoluteDifferencea(descriptors[0], descriptors2[0]); // System.Console.Write("," + percentage); var percentage = getAbsoluteDifference(a, b); System.Console.Write("," + percentage); percentage = getAbsoluteDifferenceec(a, b); System.Console.Write("," + percentage); // System.Drawing.Image img1 = System.Drawing.Image.FromFile(orgImagePath); // System.Drawing.Image img2 = System.Drawing.Image.FromFile(dupImagePath); // var percentage = Bhattacharyya.BhattacharyyaDifference(img1, img2); // percentage = percentage * 100; // percentage = Math.Round(percentage, 3); //MagickImage orgImage = new MagickImage(orgImagePath); //MagickImage dupImage = new MagickImage(dupImagePath); //percentage = orgImage.Compare(dupImage, ErrorMetric.Absolute); //System.Console.Write("," + percentage); //percentage = orgImage.Compare(dupImage, ErrorMetric.Fuzz); //System.Console.Write("," + percentage); //percentage = orgImage.Compare(dupImage, ErrorMetric.MeanAbsolute); //System.Console.Write("," + percentage); //percentage = orgImage.Compare(dupImage, ErrorMetric.MeanErrorPerPixel); //System.Console.Write("," + percentage); //percentage = orgImage.Compare(dupImage, ErrorMetric.MeanSquared); //System.Console.Write("," + percentage); //percentage = orgImage.Compare(dupImage, ErrorMetric.NormalizedCrossCorrelation); //System.Console.Write("," + percentage); //percentage = orgImage.Compare(dupImage, ErrorMetric.PeakAbsolute); //System.Console.Write("," + percentage); //percentage = orgImage.Compare(dupImage, ErrorMetric.PeakSignalToNoiseRatio); //System.Console.Write("," + percentage); //percentage = orgImage.Compare(dupImage, ErrorMetric.PerceptualHash); //System.Console.Write("," + percentage); //percentage = orgImage.Compare(dupImage, ErrorMetric.RootMeanSquared); //System.Console.Write("," + percentage); //percentage = orgImage.Compare(dupImage, ErrorMetric.Undefined); // System.Console.Write("," + percentage); System.Console.Write("\n"); } }
public rettype runalgo(string s) { string dupImagePath = s; Bitmap org0 = (Bitmap)Accord.Imaging.Image.FromFile(dupImagePath); // Bitmap org1 = org0.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb); if (greyscaleenable) { Accord.Imaging.Filters.GrayscaleBT709 gr = new Accord.Imaging.Filters.GrayscaleBT709(); org0 = gr.Apply(org0); } Bitmap org1 = org0.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb); Accord.Imaging.Filters.Difference filter = new Accord.Imaging.Filters.Difference(org1); Bitmap noiserem = org1.Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb); foreach (string filterid in algorithm) { int filterno = getfilter(filterid); if (filterno == 2) { // Console.WriteLine("AdaptiveSmoothing"); Accord.Imaging.Filters.AdaptiveSmoothing noisefilter = new Accord.Imaging.Filters.AdaptiveSmoothing(); noiserem = noisefilter.Apply(noiserem); } else if (filterno == 4) { // Console.WriteLine("AdditiveNoise"); Accord.Imaging.Filters.AdditiveNoise noisefilter = new Accord.Imaging.Filters.AdditiveNoise(); noiserem = noisefilter.Apply(noiserem); } else if (filterno == 3) { // Console.WriteLine("BilateralSmoothing"); Accord.Imaging.Filters.BilateralSmoothing noisefilter = new Accord.Imaging.Filters.BilateralSmoothing(); noiserem = noisefilter.Apply(noiserem); } if (filterno == 5) { //Bitmap gra = new Bitmap(noiserem.Width, noiserem.Height, PixelFormat.Format8bppIndexed); // Bitmap gra = new bnoiserem.Clone(System.Drawing.Imaging.PixelFormat.form); // Console.WriteLine("AdaptiveSmoothing"); Accord.Imaging.Filters.Erosion noisefilter = new Accord.Imaging.Filters.Erosion(); noiserem = noisefilter.Apply(noiserem); } else if (filterno == 6) { // Console.WriteLine("AdditiveNoise"); Accord.Imaging.Filters.Pixellate noisefilter = new Accord.Imaging.Filters.Pixellate(); noiserem = noisefilter.Apply(noiserem); } else if (filterno == 7) { // Console.WriteLine("BilateralSmoothing"); Accord.Imaging.Filters.GaussianBlur noisefilter = new Accord.Imaging.Filters.GaussianBlur(); noiserem = noisefilter.Apply(noiserem); } else if (filterno == 8) { // Console.WriteLine("BilateralSmoothing"); Accord.Imaging.Filters.GaussianSharpen noisefilter = new Accord.Imaging.Filters.GaussianSharpen(); noiserem = noisefilter.Apply(noiserem); } else { ///donothing } } // apply the filter Bitmap resultImage = filter.Apply(noiserem); double mean = 0.0;// histogram.Mean; // mean red value Accord.Statistics.Visualizations.Histogram histogram = null;; if (greyscaleenable == false) { Accord.Imaging.ImageStatistics statistics = new Accord.Imaging.ImageStatistics(resultImage); histogram = statistics.Red; mean = histogram.Mean; // mean red value } else { Accord.Imaging.Filters.GrayscaleBT709 gr = new Accord.Imaging.Filters.GrayscaleBT709(); resultImage = gr.Apply(resultImage); Accord.Imaging.ImageStatistics statistics = new Accord.Imaging.ImageStatistics(resultImage); histogram = statistics.Gray; mean = histogram.Mean; // mean red value } var lbp = new LocalBinaryPattern(blockSize: 3, cellSize: 6); // Use it to extract descriptors from the Lena image: var descriptors = lbp.ProcessImage(resultImage); double av = 0.0; foreach (var d in descriptors) { av = av + d.Average(); } av = av / descriptors.Count; rettype ret = new rettype(); ret.histogram = histogram; ret.lbpavg = av; ret.histoavg = mean; return(ret); }