private void button1_Click(object sender, EventArgs e) { Histogram histogram = img.BuildHistogram(); //low bins to 0 out int low_bins = histogram.GetNumBinsWithItems(Convert.ToInt32(img.GetHeight() * img.GetWidth() * .10)); AdvColor low_color = histogram.GetBinColor(low_bins); int high_bins = histogram.GetNumBinsWithItems(Convert.ToInt32(img.GetHeight() * img.GetWidth() * .90)); AdvColor high_color = histogram.GetBinColor(high_bins); AdvColor[,] pixels = img.HistogramStretch(low_color, high_color, histogram, ColorPlane.eGreen); SortedDictionary <AdvColor, int> bins = histogram.GetHistogram(); foreach (KeyValuePair <AdvColor, int> bin in bins) { chart1.Series["Series1"].Points.AddXY(bin.Key.GetColor(ColorPlane.eGreen), bin.Value); } RGBImage img2 = new RGBImage(pixels); img.SaveToImage(pixels, "histo_stretch.png"); Histogram histogram2 = img2.BuildHistogram(); SortedDictionary <AdvColor, int> bins2 = histogram2.GetHistogram(); foreach (KeyValuePair <AdvColor, int> bin in bins2) { chart2.Series["Series1"].Points.AddXY(bin.Key.GetColor(ColorPlane.eGreen), bin.Value); } }
private void btnLoadImage_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { img = new RGBImage(openFileDialog1.FileName, ColorPlane.eGreen); AdvColor[,] new_pixels = img.MedianFilter(img.MirrorByKernel(3, 3, img.HistogramStretch(.1, .9, ColorPlane.eGreen)), 3); //RGBImage blurred = new RGBImage(img.GaussianBlur2D(15, 15, 1.5)); RGBImage blurred = new RGBImage(img.GaussianBlur1D(1, 15, 1.5, img.GaussianBlur1D(15, 1, 1.5, new_pixels))); blurred.CalcSobel("sobel_mag.png", "sobel_dir.png"); RGBImage mag_image = new RGBImage("sobel_mag.png", ColorPlane.eGreen); RGBImage dir_image = new RGBImage("sobel_dir.png", ColorPlane.eGreen); double threshold = mag_image.CalcOtsuThreshold(); AdvColor[,] mag_image_prime = mag_image.Binarization(threshold, ColorPlane.eGreen); AdvColor[,] dir_image_prime = dir_image.Binzarization(255, ColorPlane.eGreen, mag_image_prime); mag_image.SaveToImage(mag_image_prime, "mag_image_prime.png"); dir_image.SaveToImage(dir_image_prime, "dir_image_prime.png"); RGBImage new_mag_image = new RGBImage(mag_image_prime); RGBImage new_dir_image = new RGBImage(dir_image_prime); mean = new_mag_image.Mean(ColorPlane.eGreen); textBox1.Text = "Mean: " + mean.ToString() + Environment.NewLine + "Mean - Dir: " + new_dir_image.Mean(ColorPlane.eGreen).ToString(); } }