Cartoonizing Photos

Photo cartoonizing is used in a broad range of applications and i’ve always wondered how it’s done. So, i’ve decided to make an application.

I’ve used three methods respectively: image segmentation, median filtering and edge detection. Segmentation reduces details that are not common in cartoon images, median filtering blurs the image and softens sharp edges and edge detection thickens edges.

In my implementation the most expensive process is segmentation. I’ve used k means clustering and implemented clusters using array lists. Using array lists doesn’t slow the process by itself i think but it contributes a little. However, you can change how many times the algorithm is applied to the whole image by changing the loopCount parameter. Decreasing this parameter will speed up the algorithm while reducing the accuracy of clustering. You can also change the cluster count parameter to increase or decrease details in resulting image. However this will have no effect on speed if you don’t exaggerate because the significant factors determining the speed is pixel count and loopCount. Technically speaking, cluster count has little effect in O(loopCount * totalPixelCount * clusterCount) time complexity because totalPixelCount * loopCount will be far bigger than clusterCount.

Median filtering is another time consuming process. I’ve used quickselect algorithm to find median value in the window. Time complexity is O(windowSize * pixelCount). If some sorting algorithm would be used instead it will be even slower. I’ve tried to use Huang’s median filtering algorithm to reach O(sqrt(windowSize) * pixelCount) but couldn’t manage to implement it. You can change size of the window by changing window width and window height parameters. Increasing the window size will result in a more blurred image.

Edge detection is very fast. I’ve implemented Sobel kernels edge detection. Decreasing the threshold parameter will detect more subtle edges.

bluemosque bluemosquecartoon

Leave a Reply

Your email address will not be published. Required fields are marked *