Reel.Deel
24th June 2014, 02:44
Does anyone know of an Avisynth plugin similar to this Kuwahara filter proposed on this site (http://www.kyprianidis.com/p/npar2011/)? I've searched but so far I've come up empty handed. Is it possible to achieve similar results with existing plugins?
http://www.kyprianidis.com/p/npar2011/jkyprian-npar2011-teaser.jpg
Guest
24th June 2014, 03:03
http://www.compression.ru/video/cartoonizer/index_en.html
Guest
24th June 2014, 11:48
vectorize ur pic
There does not appear to exist an Avisynth vectorizer.
raffriff42
24th June 2014, 20:13
A guy named Fred implemented the Kuwahara filter in ImageMagick (http://www.fmwconcepts.com/imagemagick/kuwahara/index.php). (scroll down)
Then of course you would need Wilbert's ImageMagick Reader / Writer for AviSynth (http://forum.doom9.org/showthread.php?t=135928).
Motenai Yoda
24th June 2014, 20:31
something with medianblur?
Wilbert
24th June 2014, 21:20
Looks like a great project ;)
http://www.fmwconcepts.com/imagemagick/kuwahara/index.php
http://en.wikipedia.org/wiki/Kuwahara_filter
http://www.cs.rug.nl/~imaging/artisticsmoothing/TIP_artistic.pdf
Perhaps i will take a stab at it tomorrow.
LoRd_MuldeR
25th June 2014, 00:29
Does anyone know of an Avisynth plugin similar to this Kuwahara filter proposed on this site (http://www.kyprianidis.com/p/npar2011/)? I've searched but so far I've come up empty handed. Is it possible to achieve similar results with existing plugins?
WarpSharp?
colours
25th June 2014, 10:02
function kuwahara(clip c, int "radius")
{
function shift(clip c, int x, int y)
{
halfx = int(x/2)
halfy = int(y/2)
c
pointresize(width(), height(), x, y).mergechroma(pointresize(width(), height(), 2*halfx, 2*halfy))
}
function copylumatochroma(clip c)
{
c
bilinearresize(width()/2, height()/2)
ytouv(last, last, c)
}
radius = default(radius, 2)
assert(radius%2 == 0, "kuwahara: radius must be even") # because I'm too lazy to make it work with odd values
r = radius/2
c
assert(isyv12(), "kuwahara: clip must be YV12")
blurred = averageblur(r, floor(r/2)) # r/2 because yv12 has halved chroma resolution
ba = shift(-r, -r)
bb = shift(r, -r)
bc = shift(-r, r)
bd = shift(r, r)
s = mt_luts(last, last, mode = "std", pixels = mt_square(r), expr = "y")
s_min = mt_logic(s.shift(0, r), s.shift(0, -r), "min")
s_min = mt_logic(s_min.shift(r, 0), s_min.shift(-r, 0), "min")
ma = mt_lutxy(s_min, s.shift(-r, -r), "x y == 255 0 ?")
mb = mt_lutxy(s_min, s.shift(r, -r), "x y == 255 0 ?")
mc = mt_lutxy(s_min, s.shift(-r, r), "x y == 255 0 ?")
md = mt_lutxy(s_min, s.shift(r, r), "x y == 255 0 ?")
mtotal = mt_average(mt_average(ma, mb), mt_average(mc, md))
ma = mt_lutxy(ma, mtotal, "x y 64 / /").copylumatochroma()
mb = mt_lutxy(mb, mtotal, "x y 64 / /").copylumatochroma()
mc = mt_lutxy(mc, mtotal, "x y 64 / /").copylumatochroma()
md = mt_lutxy(md, mtotal, "x y 64 / /").copylumatochroma()
raveragem(ba, ma, bb, mb, bc, mc, bd, md, u = 3, v = 3)
radius == 0 ? c : last
}
Disclaimer: just a normal Kuwahara filter (not the multi-scale anisotropic version as linked in the OP), only works on YV12, requires the radius to be even, and may produce incorrect results after the first frame because RAverageM is sort of buggy and unreliable.
Reel.Deel
25th June 2014, 13:28
Just tried it out but the result looks kinda blotchy:
https://www.anonimg.com/img/c42ea5519abf960e6ef2a11400d18c48.png
I guess the blotchy result is expected from a regular Kuwahara filter? (ImageJ's Kuwahara (http://rsbweb.nih.gov/ij/plugins/kuwahara.html) looks similar)
RAverageM is sort of buggy and unreliable.
No kidding, the output seems to be unusable with any radius greater than 2.
colours
25th June 2014, 14:43
The blotchiness is inherent to the basic Kuwahara filter and is not caused by any bug in RAverageM. (The bug seems to be triggered when more than one frame is requested.) There are a couple of ways to improve on the original Kuwahara filter, which is pretty much what the paper linked in the first post is all about, but they are nigh impossible to implement with just Masktools and friends.
I tried to make it blend the four square windows weighted by a negative power of their standard deviation (which should eliminate the blotching), but this turned out to be much less trivial than I expected. And would probably make it even slower than it already is—mt_luts (to calculate the standard deviation) isn't exactly the fastest filter around.
It'd be easier to write a plugin than to try implementing it through Masktools abuse, but unfortunately my coding skills leave much to be desired.
Reel.Deel
26th June 2014, 01:48
Thanks for the explanation and script, very neat how you implemented it with existing plugins (that stuff is out of my league). Too bad that MaskTools and company cannot be used efficiently. It would be nice to have a Kuwahara plugin similar to the example in the first post. On the flip side, other than creating some special effects I don't know how useful it would be for general use (maybe useful for some twisted preprocessing?).
Wilbert
27th June 2014, 23:11
My attempt: http://www.wilbertdijkhof.com/Kuwahara_v10.zip. It contains the classic and generalized Kuwahara filter. For q big enough the classic and generalized Kuwahara filter should coincide.
Documentation: see http://www.cs.rug.nl/~imaging/artisticsmoothing/TIP_artistic.pdf and examples ;)
todo: a lot ;)
0) make proper documentation
1) validate input arguments
2) look at rounding of variables
3) average color channels instead of the luma
4) add YCbCr support
5) add more/other sectors (uses currently four quadrants as in the wikipedia page)
6) the variance is calculated using a numerical unstable scheme - should replace that i presume
7) edges are left untouched
Reel.Deel
29th June 2014, 13:46
@Wilbert
Finally had some time to try it out. Thanks for taking the time to write a plugin. :)
http://s12.postimg.org/5v3wg234t/Kuwahara_1.png
http://s12.postimg.org/sl3191mcd/Kuwahara_2.png
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.