public static void TestConvolve(int kernelSize) { var bmp = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(colorImgName); var smallIm = bmp.ToImage <Bgr, byte>(); /*.Resize(new Size(320, 240), InterpolationMode.NearestNeighbor);*/ //AForge convolution takes too long var image = smallIm.Convert <Bgr, float>(); //do not measure converting byte->float and float->byte UnmanagedImage uIm = smallIm.ToAForgeImage(copyAlways: true); var floatKernel = Matrix.Random(kernelSize, kernelSize, 0, 255).ToSingle(); int[,] intKernel = floatKernel.ToImage().Convert <Gray, int>().ToArray(); measure(() => { image.Convolve(floatKernel); }, () => { AForge.Imaging.Filters.Convolution c = new AForge.Imaging.Filters.Convolution(intKernel); c.Apply(uIm); }, 2, "Image<,> Convolve", "AForge Convolve"); }
public static void TestConvolve(int kernelSize) { var bmp = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(colorImgName); var smallIm = bmp.ToImage<Bgr, byte>();/*.Resize(new Size(320, 240), InterpolationMode.NearestNeighbor);*/ //AForge convolution takes too long var image = smallIm.Convert<Bgr, float>(); //do not measure converting byte->float and float->byte UnmanagedImage uIm = smallIm.ToAForgeImage(copyAlways: true); var floatKernel = Matrix.Random(kernelSize, kernelSize, 0, 255).ToSingle(); int[,] intKernel = floatKernel.ToImage().Convert<Gray, int>().ToArray(); measure(() => { image.Convolve(floatKernel); }, () => { AForge.Imaging.Filters.Convolution c = new AForge.Imaging.Filters.Convolution(intKernel); c.Apply(uIm); }, 2, "Image<,> Convolve", "AForge Convolve"); }
/// <summary> /// Generates the filtered Image. /// </summary> public Bitmap process(Bitmap frame) { // create filter AForge.Imaging.Filters.Convolution filter = new AForge.Imaging.Filters.Convolution(matrix); // apply the filter filter.ApplyInPlace(frame); return frame; }