Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to apply K means in a mask of an image instead the whole one


I want to apply a K Means to a region of an image not squared or a rectangle. For example the source image is:

image description

now I select a custom mask:

image description

and apply K Means with k = 3:

image description

Obviously without considering the bounds (white).

Instead, what I can do with OpenCV is K Means but considering the bounds:

image description

And that messes out my final image because black is considered one colour.

Do you have any clue? Thank you in advance.