/// <summary> /// Pass a vertical and horizontal gabor filter over the superimposed images /// </summary> /// <param name="combinedPixels"></param> /// <returns></returns> public static double GaborFilter(Matrix <double> combinedPixels) { //convert to grayscale var bm = BitmapFromPixels(combinedPixels, 200); //bm = ToGrayscale(bm); var gaborFilter = new GaborFilter(); //get the vertical gabor edges gaborFilter.Theta = 0.0; var vertBitmap = gaborFilter.Apply(bm); var pixels = Array1DFromBitmap(vertBitmap).Select(x => x / 255.0).ToArray(); var vert = GetVerticalEdges(pixels); //get the horizontal gabor edges gaborFilter.Theta = Math.PI / 2; var horizBitmap = gaborFilter.Apply(bm); pixels = Array1DFromBitmap(horizBitmap).Select(x => x / 255.0).ToArray();; var horiz = GetHorizontalEdges(pixels); var sum = vert.Sum() + horiz.Sum();// + left.Sum(); return(sum); }
public static Bitmap gaborFilter(Bitmap b, GaborFilter gf) { // Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721); /*filter.Gamma = random.Next(1,5); * filter.Lambda=random.Next(1,5); * filter.Psi=random.Next(1,5); * filter.Sigma=random.Next(1,5); * filter.Theta=random.Next(1,5);*/ Bitmap bx = ImageSupporter.ColorToGrayscale(b); gf.Apply(ImageSupporter.ColorToGrayscale(bx)); // var okno = new ImageWindow(ImageSupporter.Bitmap2BitmapImage(filter.Apply(ImageSupporter.ColorToGrayscale(bx)))); // okno.Title = filter.Gamma + " " + filter.Lambda + " " + filter.Psi + " " + filter.Sigma + " " + filter.Theta; // okno.Show(); GrayscaleToRGB grayscaleToRGB = new GrayscaleToRGB(); return(grayscaleToRGB.Apply(gf.Apply(ImageSupporter.ColorToGrayscale(b)))); }
private void ButtonTest_Click(object sender, EventArgs e) { OpenFileDialog op = new OpenFileDialog(); if (op.ShowDialog() == DialogResult.OK) { var gabor = new GaborFilter(); gabor.CreateFromFile(op.FileName); pictureBox1.Image = GaborFilter.CreateFromArray(gabor.Result[GaborAngel._0]); pictureBox2.Image = GaborFilter.CreateFromArray(gabor.Result[GaborAngel._45]); pictureBox3.Image = GaborFilter.CreateFromArray(gabor.Result[GaborAngel._90]); pictureBox4.Image = GaborFilter.CreateFromArray(gabor.Result[GaborAngel._135]); PicInput.Image = Bitmap.FromFile(op.FileName); var c = network?.Classify(gabor); if (c == null) { MessageBox.Show("cannot classify"); } else { if (c.Index == 0) { lbl0.Visible = true; lbl1.Visible = false; } else { lbl0.Visible = false; lbl1.Visible = true; } } this.Width = 1089; } }
public void ProcessImageTest() { double[,] diag = Matrix.Magic(5); Bitmap input; new MatrixToImage().Convert(diag, out input); // Create a new Gabor filter GaborFilter gabor = new GaborFilter(); // Apply the filter Bitmap output = gabor.Apply(input); double[,] actual; new ImageToMatrix().Convert(output, out actual); double[,] expected = { { 0.192156862745098, 0.176470588235294, 0.254901960784314, 0.396078431372549, 0.529411764705882 }, { 0.16078431372549, 0.305882352941176, 0.494117647058824, 0.635294117647059, 0.654901960784314 }, { 0.407843137254902, 0.623529411764706, 0.737254901960784, 0.701960784313725, 0.564705882352941 }, { 0.752941176470588, 0.815686274509804, 0.713725490196078, 0.541176470588235, 0.403921568627451 }, { 0.847058823529412, 0.694117647058824, 0.505882352941176, 0.380392156862745, 0.329411764705882 } }; Assert.IsTrue(expected.IsEqual(actual, 1e-6)); }
public GaborFilter GetGaborFilterFromBank(float angle) { GaborFilter gb = new GaborFilter(); for (int i = 0; i < bank.Count - 1; i++) { if (angle > bank[i].theta && angle < bank[i + 1].theta) { if (Math.Abs(angle - bank[i].theta) < Math.Abs(angle - bank[i + 1].theta)) { bank[i].SetGaborFilter(gb); } else { bank[i + 1].SetGaborFilter(gb); } break; } else if (angle > bank[bank.Count - 1].theta) { bank[bank.Count - 1].SetGaborFilter(gb); } } return(gb); }
public static void gaborFilterRandom(Bitmap b) { GaborFilter gb = new GaborFilter(); Random random = new Random(); Bitmap bx; for (int i = 1; i < 100; i++) { gb.Gamma = random.NextDouble() * random.Next(1, 10);; gb.Lambda = random.Next(1, 10); gb.Psi = random.NextDouble(); gb.Sigma = random.Next(1, 10); gb.Theta = 0; bx = ImageSupporter.ColorToGrayscale(b); if (gb.Gamma == 0) { gb.Gamma = 0.01; } Console.WriteLine(gb.Gamma + " " + gb.Lambda + " " + gb.Psi + " " + gb.Sigma + " " + gb.Theta); try { ImageWindow iw = new ImageWindow(ImageSupporter.Bitmap2BitmapImage(gb.Apply(bx))); iw.Title = gb.Gamma + " " + gb.Lambda + " " + gb.Psi + " " + gb.Sigma + " " + gb.Theta; iw.Show(); } catch (Exception e) { e.GetBaseException(); } } }
public static void GaborFilter(Bitmap b, float gamma, float lambda, float psi, float sigma, float theta) { GaborFilter gb = new GaborFilter(); Random random = new Random(); Bitmap bx; gb.Gamma = gamma; gb.Lambda = lambda; gb.Psi = psi; gb.Sigma = sigma; gb.Theta = theta; bx = ImageSupporter.ColorToGrayscale((Bitmap)b.Clone()); Bitmap tmp = bx; tmp = gb.Apply(bx); ImageWindow iw = new ImageWindow(ImageSupporter.Bitmap2BitmapImage(tmp)); iw.Title = gb.Gamma + " " + gb.Lambda + " " + gb.Psi + " " + gb.Sigma + " " + gb.Theta; iw.Show(); }
public Bitmap gaborFilter(Bitmap b, float gamma, float lambda, float psi, float sigma, float theta) { GaborFilter filter = new GaborFilter(); Random random = new Random(); Boolean flaga = true; filter.Gamma = gamma; filter.Lambda = lambda; filter.Psi = psi; filter.Sigma = sigma; filter.Theta = theta; Bitmap bx = ImageSupporter.ColorToGrayscale(b); var okno = new ImageWindow(ImageSupporter.Bitmap2BitmapImage(filter.Apply(ImageSupporter.ColorToGrayscale(bx)))); okno.Title = filter.Gamma + " " + filter.Lambda + " " + filter.Psi + " " + filter.Sigma + " " + filter.Theta; okno.Show(); filter.Gamma = 3.0; filter.Theta = 0.0; GrayscaleToRGB grayscaleToRGB = new GrayscaleToRGB(); return(grayscaleToRGB.Apply(filter.Apply(ImageSupporter.ColorToGrayscale(b)))); }
public void SetGaborFilter(GaborFilter gb) { gb.Lambda = lambda; gb.Gamma = gamma; gb.Psi = psi; gb.Sigma = sigma; gb.Theta = theta; }
public Classifier Train(GaborFilter gaborFilter) { var c = Classify(gaborFilter, true); if (c != null) { ApplySTDP(c); } return(c); }
public void GaborTest1() { Bitmap image = Accord.Imaging.Image.Clone(Resources.lena512); GaborFilter gabor = new GaborFilter(); Bitmap result = gabor.Apply(image); // ImageBox.Show(result); Assert.IsNotNull(result); }
public void GaborTest1() { Bitmap image = Properties.Resources.lena512; GaborFilter gabor = new GaborFilter(); Bitmap result = gabor.Apply(image); // ImageBox.Show(result); Assert.IsNotNull(result); }
public static Bitmap GaborFilter(Bitmap b, float angle) { Bitmap bz = (Bitmap)b.Clone(); GaborBank gb = new GaborBank(); GaborFilter gf = gb.GetGaborFilterFromBank(angle); Bitmap bx = ImageSupporter.ColorToGrayscale((Bitmap)bz.Clone()); Bitmap filtered = gf.Apply(bx); return(ImageSupporter.GrayScaleToColor(filtered)); }
private Bitmap Gabor(Bitmap inputImage) { var gaborImageBitmap = new GaborFilter(); var GaborFilterBank = new GaborFilterBank(new Bitmap(inputImage), Settings.Default.StoreAsColorWherePossible); var gaborImage = GaborFilterBank.Filter(sizeTextBox.Text, lambdaTextBox.Text, numberOfFiltersTextBox.Text, psiTextBox.Text, sigmaTextBox.Text, gammaTextBox.Text); var nn = new Bitmap(gaborImage); return(nn); }
private double Runal(GaborFilter gaborFilter, Bitmap b) { try { Bitmap output = gaborFilter.Apply(b); Accord.Imaging.ImageStatistics statistics = new Accord.Imaging.ImageStatistics(output); var histogram = statistics.Gray; return(histogram.Mean); } catch (Exception e) { return(0); } // featuredata = featuredata + mean + ","; }
private void edgeDetect(ushort j) { cvsbmp = UtilFn.BitmapImage2Bitmap(images[j]); Grayscale gfilter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap grayImage = gfilter.Apply(cvsbmp); GaborFilter filter = new GaborFilter(); Bitmap output = filter.Apply(grayImage); imagesEdited.Add(converter.Convert(output, Type.GetType("BitmapImage"), null, null) as BitmapImage); }
/// <summary> /// <para>(Accord .NET internal call)</para> /// In image processing, a Gabor filter, named after Dennis Gabor, is a linear /// filter used for edge detection. Frequency and orientation representations /// of Gabor filters are similar to those of the human visual system, and they /// have been found to be particularly appropriate for texture representation /// and discrimination. In the spatial domain, a 2D Gabor filter is a Gaussian /// kernel function modulated by a sinusoidal plane wave. The Gabor filters are /// self-similar: all filters can be generated from one mother wavelet by dilation /// and rotation. /// </summary> /// <param name="img">Image.</param> /// <param name="size">The size of the filter</param> /// <param name="sigma">The Gaussian variance for the filter.</param> /// <param name="theta">The orientation for the filter, in radians.</param> /// <param name="lambda">The wavelength for the filter.</param> /// <param name="gamma">The aspect ratio for the filter.</param> /// <param name="psi">The phase offset for the filter.</param> /// <returns>Filtered image.</returns> public static Gray <byte>[,] GaborFilter(this Gray <byte>[,] img, int size = 3, double sigma = 2, double theta = 0.6, double lambda = 4.0, double gamma = 0.3, double psi = 1.0) { GaborFilter gf = new GaborFilter { Size = size, Sigma = sigma, Theta = theta, Lambda = lambda, Gamma = gamma, Psi = psi }; return(GaborFilter(img, gf)); }
/// <summary> /// <para>(Accord .NET internal call)</para> /// In image processing, a Gabor filter, named after Dennis Gabor, is a linear /// filter used for edge detection. Frequency and orientation representations /// of Gabor filters are similar to those of the human visual system, and they /// have been found to be particularly appropriate for texture representation /// and discrimination. In the spatial domain, a 2D Gabor filter is a Gaussian /// kernel function modulated by a sinusoidal plane wave. The Gabor filters are /// self-similar: all filters can be generated from one mother wavelet by dilation /// and rotation. /// </summary> /// <param name="img">Image.</param> /// <param name="size">The size of the filter</param> /// <param name="sigma">The Gaussian variance for the filter.</param> /// <param name="theta">The orientation for the filter, in radians.</param> /// <param name="lambda">The wavelength for the filter.</param> /// <param name="gamma">The aspect ratio for the filter.</param> /// <param name="psi">The phase offset for the filter.</param> /// <returns>Filtered image.</returns> internal static Image <TColor, TDepth> GaborFilter <TColor, TDepth>(this Image <TColor, TDepth> img, int size = 3, double sigma = 2, double theta = 0.6, double lambda = 4.0, double gamma = 0.3, double psi = 1.0) where TColor : IColor where TDepth : struct { GaborFilter gf = new GaborFilter { Size = size, Sigma = sigma, Theta = theta, Lambda = lambda, Gamma = gamma, Psi = psi }; return(GaborFilter(img, gf)); }
private List <Neuron>[] SpikeTurns(GaborFilter GaborFilter) { List <Neuron>[] list = new List <Neuron> [TimeStep]; var t = GaborFilter.Max / TimeStep; int[] steps = new int[TimeStep]; for (int i = 1; i < TimeStep; i++) { list[i - 1] = new List <Neuron>(500); steps[i - 1] = t * i; } steps[TimeStep - 1] = 256; list[TimeStep - 1] = new List <Neuron>(500); for (int i = 0; i < 4; i++) { for (int j = 0; j < Size; j++) { for (int k = 0; k < Size; k++) { var val = (GaborFilter.Result[(GaborAngel)i][j, k]); val = (val < 0 ? 0 : val > 255 ? 255 : val); var n = Layer[i, j, k]; if (val == 0) { continue; } for (int x = 1; x < TimeStep; x++) { if (val < steps[x - 1] && ((x > 1 && val >= steps[x - 2]) || x == 1)) { list[x].Add(n); n.Potential = val; break; } } } } } return(list); }
//metoda zwracająca bank filtrów gabora dla zadanej bitmapy public static List <Bitmap> gaborFilterMyBank(Bitmap bs) { List <SetValuesForGabor> bank = new List <SetValuesForGabor>(); bank.Add(new SetValuesForGabor(4, 8, 0.5f, 9.2f, 0)); bank.Add(new SetValuesForGabor(4, 8, 0.5f, 4.8f, (float)ImageSupporter.DegreeToRadian(15))); bank.Add(new SetValuesForGabor(4, 6.5f, 0.5f, 4.3f, (float)ImageSupporter.DegreeToRadian(30))); bank.Add(new SetValuesForGabor(4, 7, 0.5f, 4.3f, (float)ImageSupporter.DegreeToRadian(45))); bank.Add(new SetValuesForGabor(4, 6.5f, 0.5f, 4.3f, (float)ImageSupporter.DegreeToRadian(60))); bank.Add(new SetValuesForGabor(4, 8, 0.5f, 4.8f, (float)ImageSupporter.DegreeToRadian(75))); bank.Add(new SetValuesForGabor(4, 7, 0.5f, 4.6f, (float)ImageSupporter.DegreeToRadian(90))); bank.Add(new SetValuesForGabor(4, 7.3f, 0.5f, 4.4f, (float)ImageSupporter.DegreeToRadian(105))); bank.Add(new SetValuesForGabor(4, 6.2f, 0.5f, 3.7f, (float)ImageSupporter.DegreeToRadian(120))); bank.Add(new SetValuesForGabor(4, 7, 0.5f, 4.3f, (float)ImageSupporter.DegreeToRadian(135))); bank.Add(new SetValuesForGabor(4, 6.5f, 0.5f, 4.3f, (float)ImageSupporter.DegreeToRadian(150))); bank.Add(new SetValuesForGabor(4, 8, 0.5f, 4.8f, (float)ImageSupporter.DegreeToRadian(165))); GaborFilter gb = new GaborFilter(); Random random = new Random(); Bitmap bx; Bitmap b = (Bitmap)bs.Clone(); List <Bitmap> gaborBank = new List <Bitmap>(); bx = ImageSupporter.ColorToGrayscale(b); for (int i = 0; i < bank.Count; i++) { bank[i].SetGaborFilter(gb); gaborBank.Add(gb.Apply((Bitmap)bx.Clone())); ImageWindow im = new ImageWindow(ImageSupporter.Bitmap2BitmapImage(gaborBank[i])); im.Title = gb.Gamma + " " + gb.Lambda + " " + gb.Psi + " " + gb.Sigma + " " + gb.Theta; im.Show(); } return(gaborBank); }
public static Bitmap gaborFilter(Bitmap b, float gamma, float lambda, float psi, float sigma, float theta) { // Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721); GaborFilter filter = new GaborFilter(); Random random = new Random(); Boolean flaga = true; filter.Gamma = gamma; filter.Lambda = lambda; filter.Psi = psi; filter.Sigma = sigma; filter.Theta = theta; /*filter.Gamma = random.Next(1,5); * filter.Lambda=random.Next(1,5); * filter.Psi=random.Next(1,5); * filter.Sigma=random.Next(1,5); * filter.Theta=random.Next(1,5);*/ Bitmap bx = ImageSupporter.ColorToGrayscale(b); filter.Apply(ImageSupporter.ColorToGrayscale(bx)); // var okno = new ImageWindow(ImageSupporter.Bitmap2BitmapImage(filter.Apply(ImageSupporter.ColorToGrayscale(bx)))); // okno.Title = filter.Gamma + " " + filter.Lambda + " " + filter.Psi + " " + filter.Sigma + " " + filter.Theta; // okno.Show(); GrayscaleToRGB grayscaleToRGB = new GrayscaleToRGB(); return(grayscaleToRGB.Apply(filter.Apply(ImageSupporter.ColorToGrayscale(b)))); }
public Classifier Classify(GaborFilter gaborFilter, bool train = false) { ResetPotential(); var list = SpikeTurns(gaborFilter); Classifier winner = null; for (int t = 1; t < TimeStep + 1; t++) { foreach (var n in list[TimeStep - t]) { n.Spike = t; for (int i = 0; winner == null && i < this.Classifiers.Length; i++) { this.Classifiers[i].Potential += n.Weight[i]; } } if (winner == null && list[TimeStep - t].Count > 0) { for (int i = 0; i < this.Classifiers.Length; i++) { if (this.Classifiers[i].Potential >= this.Threshold) { this.Classifiers[i].Spike = t; winner = winner == null ? this.Classifiers[i] : winner.Potential > this.Classifiers[i].Potential ? winner : this.Classifiers[i]; } } } } if (!train) { winner = winner ?? (Classifiers[0].Potential > Classifiers[1].Potential ? Classifiers[0] : Classifiers[1]); } return(winner); }
private void gabordataextract(string s) { string dupImagePath = s; featuredata = featuredata + "\n"; Bitmap org1 = (Bitmap)Accord.Imaging.Image.FromFile(dupImagePath); Accord.Imaging.Filters.GrayscaleBT709 gr = new Accord.Imaging.Filters.GrayscaleBT709(); org1 = gr.Apply(org1); //Bitmap org2 = (Bitmap)org1.Clone(); //Accord.Imaging.Filters.Difference filter = new Accord.Imaging.Filters.Difference(org2); //var noisefilter = new Accord.Imaging.Filters.SimpleSkeletonization(); //Bitmap org0 = noisefilter.Apply(org1); //var noisefilter2 = new Accord.Imaging.Filters.BilateralSmoothing(); //org0 = noisefilter2.Apply(org0); //org0 = noisefilter2.Apply(org0); //org1 = filter.Apply(org0); GaborFilter gfilter = new GaborFilter(); { gfilter.Sigma = 2; { gfilter.Lambda = 5; ///// gfilter.Theta = 15; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 45; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 90; featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 135; featuredata = featuredata + Runal(gfilter, org1) + ","; /////////// } { gfilter.Lambda = 25; ///// gfilter.Theta = 0; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 45; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 90; featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 135; featuredata = featuredata + Runal(gfilter, org1) + ","; /////////// /// } { gfilter.Lambda = 40; ///// gfilter.Theta = 0; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 45; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 90; featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 135; featuredata = featuredata + Runal(gfilter, org1) + ","; /////////// } } { gfilter.Sigma = 4; { gfilter.Lambda = 15; ///// gfilter.Theta = 0; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 45; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 90; featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 135; featuredata = featuredata + Runal(gfilter, org1) + ","; /////////// } { gfilter.Lambda = 25; ///// gfilter.Theta = 0; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 45; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 90; featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 135; featuredata = featuredata + Runal(gfilter, org1) + ","; /////////// /// } { gfilter.Lambda = 40; ///// gfilter.Theta = 0; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 45; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 90; featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 135; featuredata = featuredata + Runal(gfilter, org1) + ","; /////////// } } { gfilter.Sigma = 5; { gfilter.Lambda = 15; ///// gfilter.Theta = 0; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 45; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 90; featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 135; featuredata = featuredata + Runal(gfilter, org1) + ","; /////////// } { gfilter.Lambda = 25; ///// gfilter.Theta = 0; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 45; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 90; featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 135; featuredata = featuredata + Runal(gfilter, org1) + ","; /////////// /// } { gfilter.Lambda = 40; ///// gfilter.Theta = 0; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 45; // Apply the filter featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 90; featuredata = featuredata + Runal(gfilter, org1) + ","; gfilter.Theta = 135; featuredata = featuredata + Runal(gfilter, org1) + ","; } } featuredata = featuredata + label; Console.WriteLine(featuredata + label); }
private void ButtonTrain_Click(object sender, EventArgs e) { FolderBrowserDialog op = new FolderBrowserDialog(); if (op.ShowDialog() == DialogResult.OK) { var files = System.IO.Directory.GetFiles(op.SelectedPath); List <Bitmap> images = new List <Bitmap>(10000); foreach (var f in files) { using (var img = (Bitmap)Bitmap.FromFile(f)) { var imgs = img.Variation(0); images.AddRange(imgs); } } ImageVariationForm frm = new ImageVariationForm(images); if (frm.ShowDialog() == DialogResult.Cancel) { return; } Gabors = new GaborFilter[images.Count]; Parallel.For(0, images.Count, i => { Gabors[i] = new GaborFilter(); Gabors[i].CreateFromBitmap(images[i]); }); Random rand = new Random(); var epochs = 70; progressBar1.Maximum = epochs * Gabors.Length; ButtonTrain.Enabled = false; progressBar1.Visible = true; Task.Run(() => { for (int i = 0; i < epochs; i++) { for (int j = 0; j < Gabors.Length; j++) { var t = network.Train(Gabors[j]); if (t == null) { this.InvokeIfRequired(f => { MessageBox.Show(f, "threshold error"); }); } this.InvokeIfRequired(f => { f.ShowResult(); progressBar1.Value = (i) * (Gabors.Length) + (j); }); Task.Delay(5).Wait(); } } this.InvokeIfRequired(f => { progressBar1.Visible = false; ButtonTest.Enabled = true; }); } ); } }
/// <summary> /// <para>(Accord .NET internal call)</para> /// In image processing, a Gabor filter, named after Dennis Gabor, is a linear /// filter used for edge detection. Frequency and orientation representations /// of Gabor filters are similar to those of the human visual system, and they /// have been found to be particularly appropriate for texture representation /// and discrimination. In the spatial domain, a 2D Gabor filter is a Gaussian /// kernel function modulated by a sinusoidal plane wave. The Gabor filters are /// self-similar: all filters can be generated from one mother wavelet by dilation /// and rotation. /// </summary> /// <param name="img">Image.</param> /// <param name="gaborFilter">Gabor filter instance. /// <para>To avoid calculating Gabor every time use this function overload that receives instance.</para> /// </param> /// <returns>Filtered image.</returns> internal static Gray <byte>[,] GaborFilter(this Gray <byte>[,] img, GaborFilter gaborFilter) { return(img.ApplyFilter(gaborFilter)); }
private void ButtonTrain_Click(object sender, EventArgs e) { FolderBrowserDialog op = new FolderBrowserDialog(); lbl0.Visible = lbl1.Visible = false; if (op.ShowDialog() == DialogResult.OK) { Random rand = new Random((int)DateTime.Now.Ticks); var files = System.IO.Directory .GetFiles(op.SelectedPath, "*.jpg", System.IO.SearchOption.AllDirectories) .OrderBy(a => rand.Next()).ToArray(); var paramFile = System.IO.Path.Combine(op.SelectedPath, "params.json"); Parameters parameters = null; if (System.IO.File.Exists(paramFile)) { parameters = Newtonsoft.Json.JsonConvert.DeserializeObject <Parameters>(System.IO.File.ReadAllText(paramFile)); } else { parameters = new Parameters(); } ParamsSet frm = new ParamsSet(parameters); if (frm.ShowDialog() != DialogResult.OK) { return; } var json = Newtonsoft.Json.JsonConvert.SerializeObject(parameters); System.IO.File.WriteAllText(System.IO.Path.Combine(op.SelectedPath, "params.json"), json); network = new Network(Threshold: parameters.Threshold, TimeStep: parameters.TimeStep, InitWeight: parameters.InitialWeight, Vartiation: parameters.Variation, PA: parameters.PA, NA: parameters.NA); List <Bitmap> images = new List <Bitmap>(10000); foreach (var f in files) { var img = (Bitmap)Bitmap.FromFile(f); { var imgs = img.Variation(0); images.AddRange(imgs); } } if (files.Length < 10) { ImageVariationForm frmVariation = new ImageVariationForm(images); if (frmVariation.ShowDialog() == DialogResult.Cancel) { return; } } var Gabors = new GaborFilter[images.Count]; Task.Run(() => { try { this.InvokeIfRequired(f => { f.Text = "Little Zhenik - making gabor filters"; }); this.InvokeIfRequired(f => { ButtonTrain.Enabled = false; progressBar1.Visible = true; }); Parallel.For(0, images.Count, i => { Gabors[i] = new GaborFilter(); Gabors[i].CreateFromBitmap(images[i]); }); this.InvokeIfRequired(f => { f.Text = "Little Zhenik"; }); } catch (Exception ex) { this.InvokeIfRequired(f => MessageBox.Show(ex.Message)); } }).ContinueWith(g => { { var epochs = parameters.Epoch; this.InvokeIfRequired(f => { progressBar1.Maximum = epochs * 2 / 3 * epochs * 1 / 3 * Gabors.Length; }); try { int p = 0; for (int i = 0; i < epochs * 2 / 3; i++) { for (int j = 0; j < Gabors.Length; j++) { for (int c = 0; c < epochs / 3; c++) { var t = network.Train(Gabors[j]); if (t == null) { this.InvokeIfRequired(f => { //MessageBox.Show(f,"threshold error"); this.Text = "Little Zhenik - Threshold"; i = epochs; j = Gabors.Length; c = epochs / 3; }); } if (p % 20 == 0) { this.InvokeIfRequired(f => { try { f.ShowResult(); progressBar1.Value = p; } catch { this.Text = "Little Zhenik - Threshold"; } }); Task.Delay(5).Wait(); } p++; } } } } catch (Exception ex) { this.InvokeIfRequired(f => MessageBox.Show(ex.Message)); } this.InvokeIfRequired(f => { progressBar1.Visible = false; ButtonTest.Enabled = true; ButtonTrain.Enabled = true; }); } }); } }
/// <summary> /// <para>(Accord .NET internal call)</para> /// In image processing, a Gabor filter, named after Dennis Gabor, is a linear /// filter used for edge detection. Frequency and orientation representations /// of Gabor filters are similar to those of the human visual system, and they /// have been found to be particularly appropriate for texture representation /// and discrimination. In the spatial domain, a 2D Gabor filter is a Gaussian /// kernel function modulated by a sinusoidal plane wave. The Gabor filters are /// self-similar: all filters can be generated from one mother wavelet by dilation /// and rotation. /// </summary> /// <param name="img">Image.</param> /// <param name="gaborFilter">Gabor filter instance. /// <para>To avoid caclulating Gabor every time use this function overload that receives instance.</para> /// </param> /// <returns>Filtered image.</returns> public static Image <Gray, byte> GaborFilter(this Image <Gray, byte> img, GaborFilter gaborFilter) { return(GaborFilterExtensionsBase.GaborFilter(img, gaborFilter)); }
/// <summary> /// <para>(Accord .NET internal call)</para> /// In image processing, a Gabor filter, named after Dennis Gabor, is a linear /// filter used for edge detection. Frequency and orientation representations /// of Gabor filters are similar to those of the human visual system, and they /// have been found to be particularly appropriate for texture representation /// and discrimination. In the spatial domain, a 2D Gabor filter is a Gaussian /// kernel function modulated by a sinusoidal plane wave. The Gabor filters are /// self-similar: all filters can be generated from one mother wavelet by dilation /// and rotation. /// </summary> /// <param name="img">Image.</param> /// <param name="gaborFilter">Gabor filter instance. /// <para>To avoid caclulating Gabor every time use this function overload that receives instance.</para> /// </param> /// <returns>Filtered image.</returns> internal static Image <TColor, TDepth> GaborFilter <TColor, TDepth>(this Image <TColor, TDepth> img, GaborFilter gaborFilter) where TColor : IColor where TDepth : struct { return(img.ApplyFilter(gaborFilter)); }