private void ApplyFilter(ConvolutionBase2D kernel) { // Convert the original image to grayscale Convolution2D image = GetOriginalImageGrays(); if (image == null) { // The original image is empty return; } Convolution2D filtered = null; if (kernel is Convolution2D) { #region Single Convolution2D kernelSingle = (Convolution2D)kernel; // This window builds kernels without gain or iterations, so make a clone with those tacked on Convolution2D kernelFinal = new Convolution2D( kernelSingle.Values, kernelSingle.Width, kernelSingle.Height, kernelSingle.IsNegPos, trkGain.Value, Convert.ToInt32(trkIterations.Value), chkExpandBorder.IsChecked.Value); filtered = Convolutions.Convolute(image, kernelFinal); if (chkSubtract.IsChecked.Value) { filtered = Convolutions.Subtract(image, filtered); } #endregion } else if (kernel is ConvolutionSet2D) { #region Set ConvolutionSet2D kernelSet = (ConvolutionSet2D)kernel; filtered = Convolutions.Convolute(image, kernelSet); #endregion } else { throw new ArgumentException("Unknown type of kernel: " + kernel.GetType().ToString()); } // Show Filtered modifiedImage.Source = Convolutions.GetBitmap(filtered, (ConvolutionResultNegPosColoring)cboEdgeColors.SelectedValue); }
private void Composite_SaveRequested(object sender, ConvolutionSet2D e) { try { AddKernel(e); } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { try { if (this.SaveRequested == null) { MessageBox.Show("There is no listener to the save event", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (_kernels.Count == 0) { MessageBox.Show("You need to add kernels before saving", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } SetOperationType operation = (SetOperationType)cboPostOperation.SelectedValue; if (operation == SetOperationType.MaxOf) { if (_kernels.Count < 2) { MessageBox.Show("MaxOf needs at least two children", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } VectorInt firstReduce = _kernels[0].GetReduction(); for (int cntr = 1; cntr < _kernels.Count; cntr++) { VectorInt nextReduce = _kernels[cntr].GetReduction(); if (firstReduce != nextReduce) { MessageBox.Show("When the operation is MaxOf, then all kernels must reduce the same amount", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } } } ConvolutionSet2D set = new ConvolutionSet2D(_kernels.ToArray(), operation); this.SaveRequested(this, set); } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
public CompositeFilter(ConvolutionSet2D set = null, bool isEditor = true) { InitializeComponent(); // Selected effect _selectEffect = new DropShadowEffect() { Direction = 0, ShadowDepth = 0, BlurRadius = 40, Color = UtilityWPF.ColorFromHex("FFEB85"), Opacity = 1, }; // Context Menu _kernelContextMenu = (ContextMenu)this.Resources["kernelContextMenu"]; // Combobox foreach (SetOperationType operation in Enum.GetValues(typeof(SetOperationType))) { cboPostOperation.Items.Add(operation); } cboPostOperation.SelectedIndex = 0; // Load set passed in if (set != null) { foreach (var child in set.Convolutions) { InsertKernel(child); } cboPostOperation.SelectedValue = set.OperationType; lblInstructions.Visibility = Visibility.Collapsed; if (!isEditor) { btnSave.Visibility = Visibility.Collapsed; } } _initialized = true; RefreshStatsPanel(); }
public MineralIdentifier() { InitializeComponent(); this.Background = SystemColors.ControlBrush; #region Tab: Single Image // Camera Trackball _trackball = new TrackBallRoam(_camera); _trackball.EventSource = grdViewPort; //NOTE: If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null) _trackball.AllowZoomOnMouseWheel = true; _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete)); _trackball.MouseWheelScale *= .1; //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius); // Mineral Types foreach (MineralType mineral in Enum.GetValues(typeof(MineralType))) { cboMineral.Items.Add(mineral); } cboMineral.SelectedIndex = 0; #endregion #region Tab: Training Data #region Mineral Types foreach (MineralType mineral in Enum.GetValues(typeof(MineralType))) { CheckBox mineralCheckbox = new CheckBox() { Content = mineral.ToString(), Tag = mineral, Margin = new Thickness(2), }; pnlMineralSelections.Children.Add(mineralCheckbox); } #endregion #region Convolutions // Gaussian Subtract AddKernel(new ConvolutionSet2D(new[] { Convolutions.GetGaussian(3, 1) }, SetOperationType.Subtract)); // MaxAbs Sobel Convolution2D vert = Convolutions.GetEdge_Sobel(true); Convolution2D horz = Convolutions.GetEdge_Sobel(false); var singles = new[] { new Convolution2D(vert.Values, vert.Width, vert.Height, vert.IsNegPos, 1), new Convolution2D(horz.Values, horz.Width, horz.Height, horz.IsNegPos, 1), }; ConvolutionSet2D set = new ConvolutionSet2D(singles, SetOperationType.MaxOf); AddKernel(set); #endregion #endregion _initialized = true; cboMineral_SelectionChanged(this, null); ResetCamera_Click(this, null); }