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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 24th June 2014, 02:44   #1  |  Link
Reel.Deel
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?

Reel.Deel is offline   Reply With Quote
Old 24th June 2014, 03:03   #2  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
http://www.compression.ru/video/cart.../index_en.html
Guest is offline   Reply With Quote
Old 24th June 2014, 11:39   #3  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
vectorize ur pic
feisty2 is offline   Reply With Quote
Old 24th June 2014, 11:48   #4  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Quote:
Originally Posted by feisty2 View Post
vectorize ur pic
There does not appear to exist an Avisynth vectorizer.
Guest is offline   Reply With Quote
Old 24th June 2014, 20:13   #5  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
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.
raffriff42 is offline   Reply With Quote
Old 24th June 2014, 20:31   #6  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709
something with medianblur?
__________________
powered by Google Translator

Last edited by Motenai Yoda; 24th June 2014 at 20:41.
Motenai Yoda is offline   Reply With Quote
Old 24th June 2014, 21:20   #7  |  Link
Wilbert
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.
Wilbert is offline   Reply With Quote
Old 25th June 2014, 00:29   #8  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
Quote:
Originally Posted by Reel.Deel View Post
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?
WarpSharp?
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊
LoRd_MuldeR is offline   Reply With Quote
Old 25th June 2014, 10:02   #9  |  Link
colours
Registered User
 
colours's Avatar
 
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
}
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.

Last edited by colours; 25th June 2014 at 10:05.
colours is offline   Reply With Quote
Old 25th June 2014, 13:28   #10  |  Link
Reel.Deel
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)

Quote:
Originally Posted by colours View Post
RAverageM is sort of buggy and unreliable.
No kidding, the output seems to be unusable with any radius greater than 2.
Reel.Deel is offline   Reply With Quote
Old 25th June 2014, 14:43   #11  |  Link
colours
Registered User
 
colours's Avatar
 
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.
colours is offline   Reply With Quote
Old 26th June 2014, 01:48   #12  |  Link
Reel.Deel
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?).
Reel.Deel is offline   Reply With Quote
Old 27th June 2014, 23:11   #13  |  Link
Wilbert
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
Wilbert is offline   Reply With Quote
Old 29th June 2014, 13:46   #14  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,664
@Wilbert

Finally had some time to try it out. Thanks for taking the time to write a plugin.



Reel.Deel is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 15:49.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.