public void OpenImage(object sender, RoutedEventArgs e) { var openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "JPG images (*.jpg)|*.jpg| PPM Images (*.ppm)|*.ppm"; if (openFileDialog.ShowDialog().Value) { if (System.IO.Path.GetExtension(openFileDialog.FileName) == ".jpg") { _bitmap = LoadImage(openFileDialog.FileName); } else { _bitmap = LoadPPMImage(openFileDialog.FileName); } _directBitmap = new DirectBitmap(_bitmap); _histogram = new Histogram(_directBitmap); GridSpectro.DataContext = _histogram; PointTransformation.InitTransform(_directBitmap); Title = openFileDialog.FileName; _zoomValue = 1.0; ImageCanvas.Source = BitmapConverter.GetBitmapSource(_bitmap); SetZoom(); } }
public override void Binarize(int level) { ResetToDefault(); PointTransformation.ConvertToGray(_bitmap, GrayConversionMode.Colorimetric); _histogram.GenerateHistograms(); int Tk = 100; while (true) { int leftSum = 0; int leftBottomSum = 0; int rightSum = 0; int rightBottomSum = 0; for (int j = 0; j <= Tk; j++) { leftSum += _histogram.RedHistogram[j] * j; leftBottomSum += _histogram.RedHistogram[j]; } for (int j = Tk + 1; j <= 255; j++) { rightSum += _histogram.RedHistogram[j] * j; rightBottomSum += _histogram.RedHistogram[j]; } if (rightBottomSum == 0) { rightBottomSum = 255; } if (leftBottomSum == 0) { leftBottomSum = 1; } if (leftSum / (2 * leftBottomSum) == rightSum / (2 * rightBottomSum)) { break; } if (Tk == (leftSum / (2 * leftBottomSum)) + (rightSum / (2 * rightBottomSum))) { break; } Tk = (leftSum / (2 * leftBottomSum)) + (rightSum / (2 * rightBottomSum)); } _levelBinarization.Binarize(Tk); }
private void UpdateColor(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "Update") { PointTransformation.AddValue(_directBitmap, Channel.Red, _colorBalanceWindow.Red); PointTransformation.AddValue(_directBitmap, Channel.Green, _colorBalanceWindow.Green); PointTransformation.AddValue(_directBitmap, Channel.Blue, _colorBalanceWindow.Blue); ImageCanvas.Source = BitmapConverter.GetBitmapSource(_directBitmap.Bitmap); } else if (e.PropertyName == "RedMultiplier" || e.PropertyName == "GreenMultiplier" || e.PropertyName == "BlueMultiplier") { PointTransformation.MultiplyByValue(_directBitmap, Channel.Red, _colorBalanceWindow.RedMultiplier); PointTransformation.MultiplyByValue(_directBitmap, Channel.Green, _colorBalanceWindow.GreenMultiplier); PointTransformation.MultiplyByValue(_directBitmap, Channel.Blue, _colorBalanceWindow.BlueMultiplier); ImageCanvas.Source = BitmapConverter.GetBitmapSource(_directBitmap.Bitmap); } }
public void Show(string filePath, OpenMode openMode) { if (openMode == OpenMode.PPM) { _bitmap = LoadPPMImage(filePath); } else { _bitmap = LoadImage(filePath); } _directBitmap = new DirectBitmap(_bitmap); _histogram = new Histogram(_directBitmap); _binarization = new LevelBinarization(_directBitmap, _histogram); GridSpectro.DataContext = _histogram; PointTransformation.InitTransform(_directBitmap); Title = filePath; ImageCanvas.Source = BitmapConverter.GetBitmapSource(_bitmap); Show(); }
public override void Binarize(int level) { ResetToDefault(); int desiredPixels = Convert.ToInt32(_bitmap.Width * _bitmap.Height * ScaleLevelToPercentage(level)); PointTransformation.ConvertToGray(_bitmap, GrayConversionMode.Colorimetric); _histogram.GenerateHistograms(); int sum = _bitmap.Width * _bitmap.Height; for (int i = 255; i >= 0; i--) { sum -= _histogram.RedHistogram[i]; if (sum < desiredPixels) { level = i + 1; break; } } _levelBinarization.Binarize(level); }
public override void Binarize(int level) { ResetToDefault(); PointTransformation.ConvertToGray(_bitmap, GrayConversionMode.Colorimetric); _histogram.GenerateHistograms(); int pixels = _bitmap.Height * _bitmap.Width; decimal Const = 255 / (decimal)pixels; int[] cdf = new int[256]; Array.Copy(_histogram.RedHistogram, cdf, 255); for (int r = 1; r <= 255; r++) { cdf[r] = cdf[r] + cdf[r - 1]; } decimal Pob = 0.0M, Pb = 0.0M; decimal Hob = 0.0M, Hb = 0.0M; for (int i = 0; i <= level; i++) { Pob += cdf[i] * Const; } for (int i = 0; i <= level; i++) { Hob += (cdf[i] * Const) / Pob * Convert.ToDecimal(Math.Log(Convert.ToDouble((cdf[i] * Const) / Pob), 2)); } for (int i = level + 1; i <= 255; i++) { Pb += cdf[i] * Const; } for (int i = level + 1; i <= 255; i++) { Hb += (cdf[i] * Const) / Pb * Convert.ToDecimal(Math.Log(Convert.ToDouble((cdf[i] * Const) / Pb), 2)); } level = (int)(-1 * (Hob + Hb)); _levelBinarization.Binarize(level); }
private void SobelFilter(object sender, RoutedEventArgs e) { PointTransformation.ConvertToGray(_directBitmap, GrayConversionMode.Colorimetric); Filters.SobelFilter(_directBitmap); ImageCanvas.Source = BitmapConverter.GetBitmapSource(_directBitmap.Bitmap); }
private void ChangeBrightness(object sender, System.Windows.Input.MouseButtonEventArgs e) { PointTransformation.ModifyBrightness(_directBitmap, _brightness); ImageCanvas.Source = BitmapConverter.GetBitmapSource(_directBitmap.Bitmap); }
private void ConvertToGrayAverage(object sender, RoutedEventArgs e) { PointTransformation.ConvertToGray(_directBitmap, GrayConversionMode.Average); ImageCanvas.Source = BitmapConverter.GetBitmapSource(_directBitmap.Bitmap); }