コード例 #1
0
        private static Convolution2D Convolute(Convolution2D conv, ToVectorInstructions instr)
        {
            Convolution2D retVal = conv;

            if (retVal.Width != retVal.Height)
            {
                int max = Math.Max(retVal.Width, retVal.Height);
                retVal = Convolutions.ExtendBorders(retVal, max, max);      // make it square
            }

            if (instr.ShouldNormalize)
            {
                retVal = Convolutions.Normalize(retVal);
            }

            if (instr.Convolution != null)
            {
                retVal = Convolutions.Convolute(retVal, instr.Convolution);
            }

            retVal = Convolutions.MaxPool(retVal, instr.ToSize, instr.ToSize);
            retVal = Convolutions.Abs(retVal);

            return(retVal);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            try
            {
                if (!chkContinuous.IsChecked.Value)
                {
                    _timer.IsEnabled = false;
                }

                int width  = trkWidth.Value.ToInt_Round();
                int height = trkHeight.Value.ToInt_Round();

                Convolution2D conv = Convolutions.ExtendBorders(_origConv, width, height);

                ShowConvolution(conv);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }