So here is the solution: Using the first image
- Find edges using
cv::Canny
- Find Contour point from these edges using
cv::findContours
with CV_RETR_CCOMP
flag (this method also returns a hierarchy array) - For all contours ignore if the contour is an edge (
hierarchy[3] != -1
) - For all valid contours find the color value in the second and third image posted in question and categorize them (use your own data structure to save that information)
- Assign new colors to pixels inside contours based on their cattegory
- Apply smoothing and you final image is ready