Create trimap from approximated mask
I would like to create a trimap to be used for matting, given an approximated (black and white) mask in which every pixel within 10 pixels of the edge would be gray.
Of course, the naive solution would be to go through the image, find all pixels that have an opposite color neighbor and paint a gray circle around it (mark every pixel within 10 pixels of each such pixel as gray).
I'm wondering if there is an easier/faster way to code it.
What I mean is - given this:
Create this:
http://docs.opencv.org/3.1.0/d8/d83/t...
How about first adding an extra black border around the image (closes the contour), findcontours on the binary image, retrieve all points of the single contour, so no cuts on straight parts, loop over those points and if they are not on the original border draw your circle?
You can try using the distance tranform for this:
Perform the distance transform on the mask, also use it on the inverse of the mask, and color grey all pixels which have a distance less than half your expected grey band width in both images.
In C++ documentation, distance transform call is: