public void ProcessImageTest2() { double[,] diag = Matrix.Magic(5); Bitmap input; new MatrixToImage().Convert(diag, out input); // Create a new Kuwahara filter Kuwahara filter = new Kuwahara(); // Apply the filter Bitmap output = filter.Apply(input); double[,] actual; new ImageToMatrix().Convert(output, out actual); string str = actual.ToString(CSharpMatrixFormatProvider.InvariantCulture); double[,] expected = { { 0.937254901960784, 0.909803921568627, 1, 0.972549019607843, 0.945098039215686 }, { 0.913725490196078, 0.984313725490196, 0.976470588235294, 0.949019607843137, 0.941176470588235 }, { 0.988235294117647, 0.980392156862745, 0.952941176470588, 0.925490196078431, 0.917647058823529 }, { 0.964705882352941, 0.956862745098039, 0.929411764705882, 0.92156862745098, 0.992156862745098 }, { 0.96078431372549, 0.933333333333333, 0.905882352941176, 0.996078431372549, 0.968627450980392 } }; Assert.IsTrue(expected.IsEqual(actual, 1e-6)); }
public mEffectKuwahara(int kernalSize) { BitmapType = mFilter.BitmapTypes.GrayscaleBT709; KernalSize = kernalSize; Effect = new Kuwahara(); Effect.Size = KernalSize; filter = Effect; }
public void KuwaharaTest1() { Bitmap image = Accord.Imaging.Image.Clone(Resources.lena512); Kuwahara kuwahara = new Kuwahara(); Bitmap result = kuwahara.Apply(image); //ImageBox.Show(result); Assert.IsNotNull(result); }
public void KuwaharaTest1() { Bitmap image = Properties.Resources.lena512; Kuwahara kuwahara = new Kuwahara(); Bitmap result = kuwahara.Apply(image); //ImageBox.Show(result); Assert.IsNotNull(result); }
/// <summary> /// Fast Implementation of Kuwahara filter. Work only with grayscale See https://en.wikipedia.org/wiki/Kuwahara_filter /// </summary> /// <param name="image"></param> /// <param name="kernelSize">Kuwahara kernel size</param> public static Bitmap GrayscaleKuwahara(this Bitmap image, int kernelSize) { if (image.PixelFormat != PixelFormat.Format8bppIndexed) { throw new NotSupportedException("Filter can be applied to binary 8bpp images only"); } Kuwahara kuwahara = new Kuwahara { Size = kernelSize }; return(kuwahara.Apply(image)); }
/// <summary> /// Kuwahara filter. /// <para>Accord.NET internal call. See: <see cref="Accord.Imaging.Filters.Kuwahara"/> for details.</para> /// </summary> /// <param name="img">Image.</param> /// <param name="size">the size of the kernel used in the Kuwahara filter. This should be odd and greater than or equal to five</param> /// <param name="blockSize">the size of each of the four inner blocks used in the Kuwahara filter. This is always half the <paramref name="size"/> minus one.</param> /// <param name="inPlace">Apply in place or not. If it is set to true return value can be omitted.</param> /// <returns>Processed image.</returns> public static Image <Gray, byte> Kuwahara(this Image <Gray, byte> img, int size = 5, int blockSize = 2, bool inPlace = false) { Kuwahara k = new Kuwahara(); return(img.ApplyFilter(k, inPlace)); }
/// <summary> /// Kuwahara filter. /// <para>Accord.NET internal call. See: <see cref="Accord.Imaging.Filters.Kuwahara"/> for details.</para> /// </summary> /// <param name="img">Image.</param> /// <param name="size">the size of the kernel used in the Kuwahara filter. This should be odd and greater than or equal to five</param> /// <param name="blockSize">the size of each of the four inner blocks used in the Kuwahara filter. This is always half the <paramref name="size"/> minus one.</param> /// <param name="inPlace">Apply in place or not. If it is set to true return value can be omitted.</param> /// <returns>Processed image.</returns> public static Gray <byte>[,] Kuwahara(this Gray <byte>[,] img, int size = 5, int blockSize = 2, bool inPlace = false) { Kuwahara k = new Kuwahara(); return(img.ApplyFilter(k, inPlace)); }
private void kuwaharaToolStripMenuItem_Click(object sender, EventArgs e) { Kuwahara customMask = new Kuwahara(this); customMask.Show(); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { IGH_Goo goo = null; Image image = new Image(); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetImage(ref image)) { return; } int mode = 0; DA.GetData(1, ref mode); double numValA = 0; DA.GetData(2, ref numValA); double numValB = 0; DA.GetData(3, ref numValB); Filter filter = new Filter(); switch ((FilterModes)mode) { case FilterModes.Additive: SetParameter(2); SetParameter(3); filter = new Additive(); image.Filters.Add(new Additive()); break; case FilterModes.Daube: SetParameter(2, "S", "Size", "[0-1] Unitized adjustment value"); SetParameter(3); filter = new Daube(numValA); image.Filters.Add(new Daube(numValA)); break; case FilterModes.SaltPepper: SetParameter(2, "N", "Noise", "[0-1] Unitized adjustment value"); SetParameter(3); filter = new SaltPepper(numValA); image.Filters.Add(new SaltPepper(numValA)); break; case FilterModes.Jitter: SetParameter(2, "R", "Radius", "[0-1] Unitized adjustment value"); SetParameter(3); filter = new Jitter(numValA); image.Filters.Add(new Jitter(numValA)); break; case FilterModes.Kuwahara: SetParameter(2, "S", "Size", "[0-1] Unitized adjustment value"); SetParameter(3); filter = new Kuwahara(numValA); image.Filters.Add(new Kuwahara(numValA)); break; case FilterModes.Posterize: SetParameter(2, "I", "Interval", "[0-1] Unitized adjustment value"); SetParameter(3); filter = new Posterize(numValA); image.Filters.Add(new Posterize(numValA)); break; case FilterModes.GaussianBlur: SetParameter(2, "X", "Sigma", "[0-1] Unitized adjustment value"); SetParameter(3, "S", "Size", "[0-1] Unitized adjustment value"); filter = new GaussianBlur(numValA, numValB); image.Filters.Add(new GaussianBlur(numValA, numValB)); break; case FilterModes.Pixellate: SetParameter(2, "W", "Width", "[0-1] Unitized adjustment value"); SetParameter(3, "H", "Height", "[0-1] Unitized adjustment value"); filter = new Pixellate(numValA, numValB); image.Filters.Add(new Pixellate(numValA, numValB)); break; case FilterModes.Blur: SetParameter(2, "D", "Divisor", "[0-1] Unitized adjustment value"); SetParameter(3, "T", "Threshold", "[0-1] Unitized adjustment value"); filter = new Blur(numValA, numValB); image.Filters.Add(new Blur(numValA, numValB)); break; } message = ((FilterModes)mode).ToString(); UpdateMessage(); DA.SetData(0, image); DA.SetData(1, filter); }