Recently I needed to extract a hand drawn object, like a child's doodle, from a camera image. The method that I found to be working reasonably good was OpenCV's EM (Expectation Maximisation) method.
The idea is that there will be pixels that are "close" enough that they are classified as one group, and hopefully with a doodle on paper, the algorithm will be able to cluster the colored pixels together against the white background of the paper.
First, I tried the algorithm on a random image and classifies it into three clusters. The result is as follows.
Hmm...looks good. The bright areas, almost white, are classified into one cluster (blue), whereas the darker and lighter colors are classified into two other clusters (red and green).
So what happens when used on a hand drawn doodle, and clustering it to two clusters (two separate background and desired object) ?
Not bad at all. There are some "holes" inside the contour since the coloring does not entirely cover the shape. This can be improved by dilation and erosion using OpenCV to obtain a final image mask.
This mask can then be applied back to the original image to extract the desired object.
If you are interested in the implementation, you can find it here.
The idea is that there will be pixels that are "close" enough that they are classified as one group, and hopefully with a doodle on paper, the algorithm will be able to cluster the colored pixels together against the white background of the paper.
First, I tried the algorithm on a random image and classifies it into three clusters. The result is as follows.
Hmm...looks good. The bright areas, almost white, are classified into one cluster (blue), whereas the darker and lighter colors are classified into two other clusters (red and green).
So what happens when used on a hand drawn doodle, and clustering it to two clusters (two separate background and desired object) ?
Not bad at all. There are some "holes" inside the contour since the coloring does not entirely cover the shape. This can be improved by dilation and erosion using OpenCV to obtain a final image mask.
This mask can then be applied back to the original image to extract the desired object.
If you are interested in the implementation, you can find it here.
Comments
Post a Comment