Ejemplo n.º 1
0
 public ImageModel(string path)
 {
     _processing = new ImageProcessing(path);
 }
Ejemplo n.º 2
0
        private void LoadFile_MenuItemClick(object sender, RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog {
                Filter = ""
            };

            var codecs = ImageCodecInfo.GetImageEncoders();
            var sep    = string.Empty;

            foreach (var c in codecs)
            {
                var codecName = c.CodecName.Substring(8).Replace("Codec", "Files").Trim();
                dlg.Filter = string.Format("{0}{1}{2} ({3})|{3}", dlg.Filter, sep, codecName, c.FilenameExtension);
                sep        = "|";
            }

            dlg.DefaultExt = ".png";

            if (_fileHasBeenSaved)
            {
                if (dlg.ShowDialog() == true)
                {
                    var fileName = dlg.FileName;

                    try
                    {
                        _currentActiveImage         = new Bitmap(fileName);
                        Img.Source                  = new BitmapImage(new Uri(fileName));
                        SaveImageMenuItem.IsEnabled = true;
                        _fileHasBeenSaved           = false;
                        _isMonochromatic            = ImageProcessing.MonochromaticValidation(_currentActiveImage);
                    }
                    catch (NotSupportedException)
                    {
                        MessageBox.Show("Unknown image format", "Warning", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                }
            }
            else
            {
                if (MessageBox.Show("Open new image without saving changes on current one?", "Warning",
                                    MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    if (dlg.ShowDialog() != true)
                    {
                        return;
                    }
                    var fileName = dlg.FileName;

                    try
                    {
                        _currentActiveImage         = new Bitmap(fileName);
                        Img.Source                  = new BitmapImage(new Uri(fileName));
                        SaveImageMenuItem.IsEnabled = true;
                        _fileHasBeenSaved           = false;
                        _isMonochromatic            = ImageProcessing.MonochromaticValidation(_currentActiveImage);
                    }
                    catch (NotSupportedException)
                    {
                        MessageBox.Show("Unknown image format", "Warning", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                }
                else
                {
                    SaveCurrentActiveImage();
                }
            }

            Apply.IsEnabled      = true;
            _imageWithoutChanges = ImageProcessing.CopyImage(_currentActiveImage);
            Revert.IsEnabled     = true;
        }
Ejemplo n.º 3
0
 private void Revert_Click(object sender, RoutedEventArgs e)
 {
     _currentActiveImage = ImageProcessing.CopyImage(_imageWithoutChanges);
     Img.Source          = Convert(_currentActiveImage);
 }
Ejemplo n.º 4
0
        private void Apply_Click(object sender, RoutedEventArgs e)
        {
            switch (_selected)
            {
            case 1:
                double.TryParse(_stdDeviationTextBox.Text, out var stdDeviation);
                if (_isMonochromatic)
                {
                    var result =
                        ImageProcessing.ImageHistogramGaussNormalizationMonochromatic(_currentActiveImage,
                                                                                      stdDeviation,
                                                                                      8);
                    Img.Source          = Convert(result);
                    _currentActiveImage = result;
                }
                else
                {
                    var result =
                        ImageProcessing.ImageHistogramGaussianNormalizationRGB(_currentActiveImage, stdDeviation,
                                                                               8);
                    Img.Source          = Convert(result);
                    _currentActiveImage = result;
                }

                break;

            case 2:
                int.TryParse(_maskSizeTextBox.Text, out var maskSize);
                int.TryParse(_orderdNumberTextBox.Text, out var orderNumber);

                if (orderNumber == 0 || maskSize == 0)
                {
                    MessageBox.Show(
                        "Invalid value of order number or mask size.\nValues must be greater than zero.",
                        "Value Error",
                        MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                if (orderNumber > maskSize * maskSize)
                {
                    MessageBox.Show(
                        "Invalid value of order number.\nValue of order number must be within the range of mask matrix range.",
                        "Value Error", MessageBoxButton.OK,
                        MessageBoxImage.Error);
                    return;
                }

                if (maskSize % 2 == 0)
                {
                    MessageBox.Show("Invalid mask size.\nSize of mask must be odd number.", "Value Error",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    return;
                }

                if (_isMonochromatic)
                {
                    var result =
                        ImageProcessing.ImageOrdfilt2Monochromatic(_currentActiveImage, maskSize, orderNumber);
                    Img.Source          = Convert(result);
                    _currentActiveImage = result;
                }
                else
                {
                    var result = ImageProcessing.ImageOrdfilt2RBG(_currentActiveImage, maskSize, orderNumber);
                    Img.Source          = Convert(result);
                    _currentActiveImage = result;
                }

                break;

            case 3:
            {
                if (!_isMonochromatic)
                {
                    _currentActiveImage = ImageProcessing.Monochromatic(_currentActiveImage);
                    _isMonochromatic    = true;
                }

                int.TryParse(_lineElementAngle.Text, out var lineAngel);
                int.TryParse(_lineElementLength.Text, out var lineLength);
                var result =
                    ImageProcessing.ImageOpeningByLineStructuralElement(_currentActiveImage, lineAngel, lineLength);
                Img.Source          = Convert(result);
                _currentActiveImage = result;
                break;
            }

            case 4:
            {
                if (!_isMonochromatic)
                {
                    _currentActiveImage = ImageProcessing.Monochromatic(_currentActiveImage);
                    _isMonochromatic    = true;
                }

                var result = ImageProcessing.ImageFillHoles(_currentActiveImage);
                Img.Source          = Convert(result);
                _currentActiveImage = result;
                break;
            }

            case 0:
                MessageBox.Show("Please select editing option", "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                break;

            default:
                var messageBoxResult =
                    MessageBox.Show("Unknown Error", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                if (messageBoxResult == MessageBoxResult.OK)
                {
                    Application.Current.Shutdown();
                }
                break;
            }
        }