private void AddKernel(ConvolutionBase2D kernel) { Border border = Convolutions.GetThumbnail(kernel, 40, _kernelContextMenu); //if (!string.IsNullOrEmpty(tooltipHeader)) //{ // // For simple (not composite) kernels, it's the image that gets the tooltip. So if this is one of those, add to the tooltip // if (border.Child is Image) // { // string existingTooltip = ((Image)border.Child).ToolTip as string; // if (!string.IsNullOrEmpty(existingTooltip)) // { // ((Image)border.Child).ToolTip = tooltipHeader + "\r\n" + existingTooltip; // } // else // { // border.ToolTip = tooltipHeader; // } // } // else // { // border.ToolTip = tooltipHeader; // } //} // Store them panelKernels.Children.Add(border); _kernels.Add(kernel); }
private static double[] GetTrainingImage(FeatureRecognizer_Image image, ConvolutionBase2D kernel) { // Enlarge the initial image by the kernel's reduction so that after convolution, it is the desired size VectorInt reduction = kernel.GetReduction(); if (reduction.X != reduction.Y) { throw new ApplicationException(string.Format("Kernel should be square: {0}x{1}", reduction.X, reduction.Y)); } BitmapSource bitmap = new BitmapImage(new Uri(image.Filename)); bitmap = UtilityWPF.ResizeImage(bitmap, IMAGESIZE + reduction.X, true); Convolution2D retVal = UtilityWPF.ConvertToConvolution(bitmap, 1d); if (retVal.Width != retVal.Height) { retVal = Convolutions.ExtendBorders(retVal, IMAGESIZE + reduction.X, IMAGESIZE + reduction.X); //NOTE: width or height is already the desired size, this will just enlarge the other to make it square } retVal = Convolutions.Convolute(retVal, kernel); retVal = Convolutions.Abs(retVal); // It looks better when it's black on white double[] inverted = retVal.Values. Select(o => 1d - o). ToArray(); return(inverted); }
private void KernelEdit_Click(object sender, RoutedEventArgs e) { try { Tuple <Border, int> kernel = GetSelectedKernel(_kernelContextMenu.PlacementTarget); if (kernel == null) { MessageBox.Show("Couldn't identify filter", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } ConvolutionBase2D selected = _kernels[kernel.Item2]; if (selected is Convolution2D) { #region Single ImageFilterPainter editor = new ImageFilterPainter(); editor.SaveRequested += Painter_SaveRequested; editor.Closed += Child_Closed; _childWindows.Add(editor); editor.EditKernel((Convolution2D)selected); editor.Show(); #endregion } else if (selected is ConvolutionSet2D) { #region Set CompositeFilter composite = new CompositeFilter((ConvolutionSet2D)selected) { // I don't want this one on top //Owner = this, // setting this so it stays on top of this window }; composite.SaveRequested += Composite_SaveRequested; composite.Closed += Child_Closed; _childWindows.Add(composite); composite.Show(); #endregion } else { MessageBox.Show("Unknown type of kernel: " + _kernels[kernel.Item2].GetType().ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
public ToVectorInstructions(int[] fromSizes, int toSize, ConvolutionBase2D convolution = null, bool shouldNormalize = false, bool isColor2D = false) { this.FromSizes = fromSizes; this.ToSize = toSize; this.Convolution = convolution; this.ShouldNormalize = shouldNormalize; this.IsColor2D = isColor2D; }
public HopfieldNetwork() { InitializeComponent(); _trainKernel = Convolutions.GetEdgeSet_GuassianThenEdge(5); _initialized = true; }
private void AddKernel(ConvolutionBase2D kernel) { Border border = Convolutions.GetThumbnail(kernel, 40, null); // Store them panelKernels.Children.Add(border); _kernels.Add(kernel); }
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 InsertKernel(ConvolutionBase2D kernel, int index = -1) { Border border = Convolutions.GetThumbnail(kernel, 80, _kernelContextMenu); if (index < 0) { panel.Children.Add(border); _kernels.Add(kernel); } else { panel.Children.Insert(index, border); _kernels.Insert(index, kernel); } }
/// <param name="itemDimensions"> /// The width, height, depth, etc of each item /// </param> /// <param name="convolution"> /// This gives a chance to run an edge detect, or some other convolution /// TODO: Support convolutions that can handle arbitrary dimensions /// </param> /// <param name="shouldNormalize"> /// Forces all inputs to go between 0 and 1. /// NOTE: Only do this if the inputs come from varied sources /// </param> /// <param name="dupeDistance"> /// If two items are closer together than this, they will be treated like they are the same. /// NOTE: If all the inputs are 0 to 1 (or even -1 to 1), then the default value should be fine. But if the /// inputs have larger values (like 0 to 255), you would want a larger min value /// </param> public SOMList(int[] itemDimensions, ConvolutionBase2D convolution = null, bool shouldNormalize = false, bool discardDupes = true, double dupeDistance = .001, bool isColor2D = false) { _instructions = new ToVectorInstructions(itemDimensions, GetResize(itemDimensions), convolution, shouldNormalize, isColor2D); _dupeDistSquared = dupeDistance * dupeDistance; }
public DragDataObject(int index, Border control, ConvolutionBase2D kernel) { this.Index = index; this.Control = control; this.Kernel = kernel; }