Ejemplo n.º 1
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;
            }
        }