Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A quick and dirty solution (maybe s.o. else knows sth more elegant):

// assume you loaded img as color-image
// and that mask is 0 in the areas which you don't want
std::vector<cv::Vec3b> points;
for( int y = 0; y < img.rows; y++){
    for( int x = 0; x < img.rows; x++){
        if ( mask(y,x) != 0 ) 
            points.push_back(img.at<cv::Vec3b>(y,x));
    }   
}

// now run kmeans using the points as input-data

A quick and dirty solution (maybe s.o. else knows sth more elegant):

// assume you loaded img as color-image
// and that mask is 0 in the areas which you don't want
std::vector<cv::Vec3b> points;
for( int y = 0; y < img.rows; y++){
    for( int x = 0; x < img.rows; x++){
        if ( mask(y,x) != 0 ) 
            points.push_back(img.at<cv::Vec3b>(y,x));
    }   
}

// now run kmeans using the points as input-data

as soon as you have the labels you can go through your image as above and set the image according to the label.