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:
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):
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):
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?
Approximate a tracing effect to "clean" an image
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Approximate a tracing effect to "clean" an image
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.
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.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Approximate a tracing effect to "clean" an image
There are several other options.
Input:
1) Kuwahara filtering (fast)
2) mean shift (slow - iterative)
3) kmeans script (slow - iterative)
Input:
1) Kuwahara filtering (fast)
Code: Select all
convert image.jpg -kuwahara 5 image_kuwahara5.png
Code: Select all
convert image.jpg -kuwahara 9 image_kuwahara9.png
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
3) kmeans script (slow - iterative)
Code: Select all
kmeans -n 16 -m 5 image.jpg image_kmeans16.png
Re: Approximate a tracing effect to "clean" an image
Thanks, kuwahara looks promising!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Approximate a tracing effect to "clean" an image
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