Mean Shift Segmentation

Posted: June 17, 2011 at 11:17 am

While working through the conceptual aspects of the project I have also been exploring alternative segmentations methods. The more I think about background subtraction the more I think it would restrict the material available to the system from which to construct dream images.

Now that the segmentation is reasonable, especially considering the difficult plant edges and semi-transparency, the next step is to convert these edges to to contours and break them into individual components. One issue with this segmentation method is that it is far too slow for real-time use. Here is the code (based on the sample included in opencv 2.2):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"

using namespace cv;
using namespace std;

Mat img, res, element;

int main(int argc, char** argv)
{

   namedWindow( "window", CV_WINDOW_NORMAL );
   img = imread( argv[1] );
   pyrMeanShiftFiltering( img, res, 10, 35, 3);
   imwrite("output.png", res);
   imshow( "window", res );

   waitKey();

   return 0;
}