private void OtsuBinarize_Click(object sender, RoutedEventArgs e)
 {
     PutToGreyScaleComboBox(ColorComoBox.SelectedIndex);
     int[] histogram = Histogram.calculateHistograms(currentImage.bitmap)[ColorComoBox.SelectedIndex];
     Binarization.otsuBinarization(currentImage.bitmap, histogram);
     imgPhoto.Source = ImageSourceForBitmap(currentImage.bitmap);
 }
        private void ManualyBinarize_Click(object sender, RoutedEventArgs e)
        {
            int manualValue = Int32.Parse(manualBinarizationValueBox.Text);

            PutToGreyScaleComboBox(ColorComoBox.SelectedIndex);
            Binarization.manualBinarization(currentImage.bitmap, manualValue);

            imgPhoto.Source = ImageSourceForBitmap(currentImage.bitmap);
        }
        public static void otsuBinarization(Bitmap bitmap, int[] histogram)
        {
            int maxVariance = 0, tmpMaxVariance, threshold = 0;

            double[] cumulativeDistribution = CumulativeDistribution(histogram);
            double   foregroundPixels, backgroundPixels;
            int      averageBackground, averageForeground;

            for (int i = 0; i < 256; i++)
            {
                foregroundPixels  = GetCountPixels(cumulativeDistribution, i + 1, histogram.Length);
                backgroundPixels  = GetCountPixels(cumulativeDistribution, 0, i);
                averageBackground = getAveragePixels(cumulativeDistribution, 0, i, backgroundPixels);
                averageForeground = getAveragePixels(cumulativeDistribution, i + 1, histogram.Length, foregroundPixels);
                tmpMaxVariance    = (int)(foregroundPixels * backgroundPixels * Math.Pow(averageForeground - averageBackground, 2));
                if (maxVariance < tmpMaxVariance)
                {
                    maxVariance = tmpMaxVariance;
                    threshold   = i;
                }
            }
            Binarization.manualBinarization(bitmap, threshold);
        }
 private void BernsenBinarize_Click(object sender, RoutedEventArgs e)
 {
     PutToGreyScaleComboBox(ColorComoBox.SelectedIndex);
     Binarization.BernsenBinarization(currentImage.bitmap, Int32.Parse(ContrastValueBox.Text), Int32.Parse(ThresholdValueBox.Text));
     imgPhoto.Source = ImageSourceForBitmap(currentImage.bitmap);
 }