Java apply cartoonizer effect

2.9k views Asked by At

I want create a image filter which will create a cartoonizer effect. What I am trying is something like this -

cartoonizer

Please help with the procedure to achieve this. I need this to be done in Java.

If a working code is not possible, at least give me some idea how generally this things are done. As there is a lot of websites do this now a days, I assume this should not be too difficult.

What I have tried so far is this -

BufferedImage in = ImageIO.read(new File(basePath + "in11.jpg"));
BufferedImage out = new BufferedImage(in.getWidth(), in.getHeight(), BufferedImage.TYPE_INT_ARGB);

EdgeFilter edgeFilter = new EdgeFilter();
edgeFilter.filter(in, out);

GrayscaleFilter grayscaleFilter = new GrayscaleFilter();
grayscaleFilter.filter(out, out);

InvertFilter invertFilter = new InvertFilter();
invertFilter.filter(out, out);

But this is a code for create a sketch effect (I am using JHLabs Filters from this link ). Output is this -

output-sketch

Now my assumption is if I able to implement a filter which will decrease the number of colours in my image and then if I overlay it with the sketch image I might get my desire effect. But I don't know hot to implement that.

1

There are 1 answers

4
Vit On
  • repaint object using palette with small amount of color (k-means method is suitable to find which colors to use, but you should determine a number of colors)
  • optional: use morphological operations to filter noise (dilation + erosion)
  • find edges (Canny etc)
  • simplify edges using any of contour simplification algorithm

Another way is to use bilateral smoothing filter on its extreme paramters (smooth very much): see example and code.

OpenCV lib is ok for this, it also supports Java, or you can use JavaCV as Java-openCV proxy.