Actually I have already asked this question in official Q&A but didn’t get any answer yet.
My task is to use kmeans clusterization not for the whole image but only for it’s masked part. So as input I have two images:
- Masked image.
- Image converted to Lab color space.
And if I clusterize image on n clusters, after clusterization with mask I want to have image with n+1 clusters (+1 because of mask).
Of course I researched and googled it but found nothing.
Thanks for any advice.
Create another image, copy the data unmasked data in it, and use this matrix to perform your kmeans. This is how it goes:
[edit]
The following does not work, it only black-out pixels in the mask, but tmp has same dimension as original image.
cv::Mat tmp;
labImage.copyTo(tmp, mask);
You should allocate the tmp matrix beforehand, and fill it with a loop over the mask:
[/edit]