How to eliminate pixels with large separation

asked 2016-07-07 09:09:25 -0500

kdlsw gravatar image

I applied a k_means to some image, divided it into 5 regions, according to the colour. Then for each region, I apply k-means again, with the pixels' coordinate as input, divide each region in to two parts.

for(int i=0;i<5;i++){

Mat_<float> loc_centroid;

Mat loc_name;


kmeans(loc_name,2,loc_label,cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0), 1, cv::KMEANS_PP_CENTERS,loc_centroid);

This is what I got for the outcome. image description

Blue part are the region from colour k-means. Two red circles (bit hard to see, sorry), are the centers from coordinate cluster.

The problem is, the lower center. This center obviously is contributed by those colour regions on the floor. Which is not required. In this case, only the data from that human is needed.

I tried standard deviation, to rule those clusters out. The x coordinate as input, if the pixel in one region cluster is too widely separated, I can eliminate it.

for (int j=0; j<loc_label.cols; j++){
case 0:


case 1:




Scalar mean0;
Scalar stddev0;
meanStdDev (two_loc0 , mean0, stddev0);

Scalar mean1;
Scalar stddev1;
meanStdDev (two_loc1 , mean1, stddev1);

But the std is a bit different from my expectation, those regions with a large separation, like the picture floor, sometimes do not have a large std, some small concentrated regions have a high std (I guess it's due to the small sample points as the region is small?)

Besides the possibility that I made some mistakes in the code, is there any manageable way for this issue? To eliminate colour blocks with large separation (like the floor), and only keep the concentrated part (the body).

Any suggestions will be appreciated, thanks!

edit retag flag offensive close merge delete