morphologyEx dilate and erode isn't working properly..

asked 2015-11-10 03:55:03 -0600

215 gravatar image

updated 2015-11-10 04:01:30 -0600

I am at the moment trying to dilate and erode an binary image, but it doesn't seem to me that OpenCV is even trying to do so, am I applying incorrectly?

Here is the code:

  Mat src = imread();
  Mat Temp = ColorTransform(src,8);
  cvtColor(Temp,Temp,CV_BGR2GRAY);
   int morph_elem = 0;
    int morph_size = 11;
    int morph_operator = 0;
    int const max_operator = 4;
    int const max_elem = 2;
    int const max_kernel_size = 21;

   Mat temp= ColorTransForm(src,8);
   cvtColor(temp,temp, CV_BGR2GRAY);
   Mat bin;
   Mat dones;
   double thresh = 250;
   double maxValue = 255;
   threshold(temp,bin, thresh, maxValue, THRESH_BINARY);

  for(int  j = 0; j< 50 ; j++)
  {
     cout <<"Morph: " << j<<endl;
     Mat element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );

     morphologyEx(bin,dones, MORPH_OPEN,100);
     namedWindow("result",WINDOW_NORMAL);
     imshow("result",temp);
     namedWindow("bin", WINDOW_NORMAL);
     imshow("bin",bin);
     namedWindow("Morphed", WINDOW_NORMAL);
     imshow("Morphed",dones);
     waitKey(0);
  }

The Binary image is the same as the Morphology image? How come?

image description

This is what i want to detect image description

edit retag flag offensive close merge delete

Comments

3

you're never using your kernel / element ? (but pass in 100 instead)

have a look at the docs

berak gravatar imageberak ( 2015-11-10 04:05:10 -0600 )edit
1

Side comment: if you MORPH_OPEN that image, all those points will disappear. I'm not sure how you're planning to detect that zone

LorenaGdL gravatar imageLorenaGdL ( 2015-11-10 04:17:49 -0600 )edit

using findContours.. Sorry. I use MORPH_CLOSE

215 gravatar image215 ( 2015-11-10 04:19:20 -0600 )edit

how would you connect them?

215 gravatar image215 ( 2015-11-10 08:09:38 -0600 )edit