Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
24th June 2014, 02:44 | #1 | Link |
Registered User
Join Date: Mar 2012
Location: Texas
Posts: 1,664
|
Kuwahara filter for Avisynth?
Does anyone know of an Avisynth plugin similar to this Kuwahara filter proposed on this site? I've searched but so far I've come up empty handed. Is it possible to achieve similar results with existing plugins?
|
24th June 2014, 20:13 | #5 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
A guy named Fred implemented the Kuwahara filter in ImageMagick. (scroll down)
Then of course you would need Wilbert's ImageMagick Reader / Writer for AviSynth. |
24th June 2014, 21:20 | #7 | Link |
Moderator
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
|
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. |
25th June 2014, 00:29 | #8 | Link | |
Software Developer
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
|
Quote:
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ |
|
25th June 2014, 10:02 | #9 | Link |
Registered User
Join Date: Mar 2014
Posts: 308
|
Code:
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 } Last edited by colours; 25th June 2014 at 10:05. |
25th June 2014, 13:28 | #10 | Link |
Registered User
Join Date: Mar 2012
Location: Texas
Posts: 1,664
|
Just tried it out but the result looks kinda blotchy:
I guess the blotchy result is expected from a regular Kuwahara filter? (ImageJ's Kuwahara looks similar) No kidding, the output seems to be unusable with any radius greater than 2. |
25th June 2014, 14:43 | #11 | Link |
Registered User
Join Date: Mar 2014
Posts: 308
|
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. |
26th June 2014, 01:48 | #12 | Link |
Registered User
Join Date: Mar 2012
Location: Texas
Posts: 1,664
|
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?).
|
27th June 2014, 23:11 | #13 | Link |
Moderator
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
|
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/artist...P_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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|