Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

morphologyEx dilate and erode isn't working properly..

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

morphologyEx dilate and erode isn't working properly..

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