Zeve
Zeve

Reputation: 23

Image processing with opening and closing using emgu 3.0, MorphologyEx, c#

How can I implement image processing with opening and closing using new emgu version?

i found this one: www.stackoverflow.com/questions/11567350/opening-and-closing-using-opencv/

but i cant use "StructuringElementEx" anymore and the new "image.MorphologyEx()" method needs a little more values.

I also tried it with .dilate and .erode but this is only possible with a 3x3 rectangular shape which wasn't quite successful.

An "updated" example would be great!

Upvotes: 1

Views: 9829

Answers (2)

Oscar Rangel
Oscar Rangel

Reputation: 1066

This function will not take a Mat in EMGU 3.1

I am using this ones.

// Opening (erode->dilate) para quitar ruido.
// get rid of small objects
Mat kernelOp = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3,3), new Point(-1, -1));
CvInvoke.MorphologyEx(ThresholdMask, _Morphology, MorphOp.Open, kernelOp, new Point(-1, -1), 1, BorderType.Default, new MCvScalar());

// Closing (dilate -> erode) para juntar regiones blancas.
Mat kernelCl = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(11, 11), new Point(-1, -1));
CvInvoke.MorphologyEx(_Morphology, _Morphology, MorphOp.Close, kernelCl, new Point(-1, -1), 1, BorderType.Default, new MCvScalar());

Upvotes: 0

Lê Quang Duy
Lê Quang Duy

Reputation: 787

Also have the same problem with you in using MorphologyEx of Emgu CV 3.0
I found this test code in the Github.
Hope this help!

[Test]
  public void TestMorphEx()
  {
     Mat kernel1 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Cross, new Size(3, 3), new Point(1, 1));
     Matrix<byte> kernel2 = new Matrix<byte>(new Byte[3, 3] { { 0, 1, 0 }, { 1, 0, 1 }, { 0, 1, 0 } });
     //StructuringElementEx element2 = new StructuringElementEx(new int[3, 3] { { 0, 1, 0 }, { 1, 0, 1 }, { 0, 1, 0 } }, 1, 1);
     Image<Bgr, Byte> tmp = new Image<Bgr, byte>(100, 100);
     Image<Bgr, Byte> tmp2 = tmp.MorphologyEx(Emgu.CV.CvEnum.MorphOp.Gradient, kernel1, new Point(-1, -1), 1, CvEnum.BorderType.Default, new MCvScalar());
     Image<Bgr, Byte> tmp3 = tmp.MorphologyEx(Emgu.CV.CvEnum.MorphOp.Gradient, kernel2, new Point(-1, -1), 1, CvEnum.BorderType.Default, new MCvScalar());
     //Image<Bgr, Byte> tmp2 = tmp.MorphologyEx(element1, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_GRADIENT, 1);
     //Image<Bgr, Byte> tmp3 = tmp.MorphologyEx(element2, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_BLACKHAT, 1);
  }

Upvotes: 4

Related Questions