Page 1 of 1

Approximate a tracing effect to "clean" an image

Posted: 2019-01-02T10:29:01-07:00
by BigNoub
I'm using Imagemagick 7.0.8-14 on ubuntu 16.04

I have a jpg that is quite noisy and blurry with lots of shapes and colors:

Image

I would like to "clean" it, meaning remove the noise in the white areas, make sharper edges, maybe reduce the number of colors in the image. Basically I would like the image to appear as if it was a vector illustration that had been rasterized. I was able to get to this with potrace (by tracing then converting back to jpg):

Image

It's not bad, but it's very slow, and I'd like to still reduce the complexity of the image if possible, to obtain something like this (roughly painted in photoshop just to give you an idea):

Image

How would you approach such a task? Do I necessarily have to try and test with the sharp, denoise, reduce colors parameters, or is there a command / script to do the heavy-lifting?

Re: Approximate a tracing effect to "clean" an image

Posted: 2019-01-02T11:27:40-07:00
by snibgo
You want to blur the image heavily where it is fairly smooth, and sharpen it where it is fairly sharp. This is often called "adaptive blur" or "adaptive sharpen". See Adaptive contour blur and sharpen.

A more complex method is shown at Cartoon and texture.

Broadly, the technique is to decide what blur does what you want (eg "-blur 0x10") in blurry areas, and what sharpening does what you want for the edges. Then blend those images with a mask.

Re: Approximate a tracing effect to "clean" an image

Posted: 2019-01-02T11:59:50-07:00
by fmw42
There are several other options.

Input:
Image


1) Kuwahara filtering (fast)

Code: Select all

convert image.jpg -kuwahara 5 image_kuwahara5.png
Image

Code: Select all

convert image.jpg -kuwahara 9 image_kuwahara9.png
Image


2) mean shift (slow - iterative)

Code: Select all

convert image.jpg -colorspace YIQ -monitor -mean-shift 21x21+10% +monitor -set colorspace YIQ -colorspace sRGB image_mshift21yiq.png
Image


3) kmeans script (slow - iterative)

Code: Select all

kmeans -n 16 -m 5 image.jpg image_kmeans16.png
Image

Re: Approximate a tracing effect to "clean" an image

Posted: 2019-01-02T13:47:07-07:00
by BigNoub
Thanks, kuwahara looks promising!

Re: Approximate a tracing effect to "clean" an image

Posted: 2019-01-02T14:07:26-07:00
by fmw42
Here is the results from adaptive-sharpening as snibgo had suggested. It also is fast.

Code: Select all

convert image.jpg -adaptive-sharpen 0x35 image_as35.png
Image