Ask Your Question

amichaut's profile - activity

2014-10-14 11:05:05 -0600 asked a question Watershed not optimal (C++ implementation)

Hi,

I have implemented a Watershed algorithm on a test file. Here is my markers file: C:\fakepath\test_shape.002.jpg Here is my image file: C:\fakepath\test_shape.001.jpg And here is my output file: C:\fakepath\cell.tiff

As you can see the limit is not very accurate. Do you think there is something I can do? Here's my code:

  Mat markers(img.size(), CV_32S);
  markers = Scalar::all(0);
  for(int i=0; i<marker_contours.size(); ++i)
  {
    drawContours(markers, marker_contours, i, Scalar::all(i+1), CV_FILLED, 8, vector<Vec4i>(),0,Point());
  }
  Mat wshed_img = Mat::zeros(img.size(),CV_8UC3);
  cvtColor(img,wshed_img,CV_GRAY2BGR);
  watershed(wshed_img,markers);
  // draw the watershed image
  for( int i = 0; i < markers.rows; i++ )
  {
    for( int j = 0; j < markers.cols; j++ )
    {
      int index = markers.at<int>(i,j);
      if( index == -1 )
      {
        img.at<uchar>(i,j) = uchar(0);
      }
    }
  }

Many thanks

2014-09-15 10:10:32 -0600 received badge  Supporter (source)