private static Mat CreateKernal(kernal kernal, System.Drawing.Size size) { switch (kernal) { case kernal.Vertical: var verisize = new System.Drawing.Size(1, size.Height); return(CvInvoke.GetStructuringElement(ElementShape.Rectangle, verisize, new System.Drawing.Point(-1, -1))); case kernal.Horizontal: var horisize = new System.Drawing.Size(size.Width, 1); return(CvInvoke.GetStructuringElement(ElementShape.Rectangle, horisize, new System.Drawing.Point(-1, -1))); case kernal.Cross: return(CvInvoke.GetStructuringElement(ElementShape.Cross, size, new System.Drawing.Point(-1, -1))); case kernal.Rect: return(CvInvoke.GetStructuringElement(ElementShape.Rectangle, size, new System.Drawing.Point(-1, -1))); default: return(CvInvoke.GetStructuringElement(ElementShape.Cross, size, new System.Drawing.Point(-1, -1))); } }
public static Func <Image <Gray, byte>, int, Image <Gray, byte> > FnMorp(morpOp op, kernal kernal) { var morp = new Func <Image <Gray, byte>, int, Image <Gray, byte> >((img, size) => { if (size == 0) { size = 3; } var ken = CreateKernal(kernal, new System.Drawing.Size(size, size)); return(img.MorphologyEx(CreateMorpOp(op), ken, new System.Drawing.Point(-1, -1), 1, BorderType.Default, new MCvScalar(0))); }); return(morp); }
public static Image <Gray, byte> Morp(Image <Gray, byte> rootimg, morpOp op, int size, kernal kernal) { if (size == 0) { size = 1; } var kern = CreateKernal(kernal, new System.Drawing.Size(size, size)); return(rootimg.MorphologyEx(CreateMorpOp(op), kern, new System.Drawing.Point(-1, -1), 1, BorderType.Default, new MCvScalar(0))); }