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 AddImage(string filename, string category) { string uniqueID = Guid.NewGuid().ToString(); // Try to read as a bitmap. The caller should have a catch block that will handle non images (better to do this now than bomb later) BitmapSource bitmap = new BitmapImage(new Uri(filename)); // Build entry FeatureRecognizer_Image entry = new FeatureRecognizer_Image() { Category = category, UniqueID = uniqueID, Filename = filename, //ImageControl = FeatureRecognizer.GetTreeviewImageCtrl(new BitmapImage(new Uri(filename))), //Bitmap = bitmap, }; // Store it //FeatureRecognizer.AddImage(entry, _images, treeImages, cboImageLabel); _images.Add(entry); }