View Full Version : GenericFilters [Now part of VS core]
Chikuzen
2nd January 2013, 18:55
GenericFilters-0.7.0.zip (http://www.mediafire.com/download/pxqrjpq1800lmd5/GenericFilters-0.7.0.zip)
https://github.com/chikuzen/GenericFilters
GenericFilters is a set of common image-processing filters.
I think that the necessity of using masktools2 of avisynth will decrease considerably if this plugin and std.functions are used together.
Cross reference list of masktools2 and GenericFilters
mt_edge - generic.Convolution/generic.Sobel/generic.Prewitt/generic.TEdge
mt_invert - generic.Invert
mt_binarize - generic.Binarize
mt_expand - generic.Maximum
mt_inpand - generic.Minimum
mt_inflate - generic.Inflate
mt_deflate - generic.Deflate
mt_clamp - generic.Limiter
mt_convolution - generic.Convolution/generic.ConvolutionHV
mt_hysteresis - generic.Hysteresis
mt_lut - std.Lut/std.Expr
mt_lutxy -std.Lut2/std.Expr
mt_lutxyz - std.Expr
mt_merge - std.MaskedMerge
EDIT:
20130812 update to 0.7.0
Myrsloik
2nd January 2013, 20:26
It is my duty to shamelessly bump this post since it renders masktools almost completely obsolete. We're now one big step closer to getting completely native vapoursynth scripts for useful things.
Daemon404
2nd January 2013, 23:33
It is my duty to shamelessly bump this post since it renders masktools almost completely obsolete. We're now one big step closer to getting completely native vapoursynth scripts for useful things.
I dream of a native OS X / Linux QTGMC.
sl1pkn07
3rd January 2013, 21:53
https://github.com/chikuzen/GenericFilters/issues/1
06_taro
4th January 2013, 03:03
Another thing is, I use the following script to compare the output of mt_edge and generic.Convolution.
clip = something
c1 = core.avs.mt_edge(clip, '1 2 1 0 0 0 -1 -2 -1 1', 0, 255)
c2 = core.generic.Convolution(clip, [1, 2, 1, 0, 0, 0, -1, -2, -1], planes=0)
clip = core.std.Interleave([c1, c2])
clip = core.std.ShufflePlanes(clip, planes=0, format=vs.GRAY)
I originally think the result of the two will be identical, but it's not. However I am no expert at matrix convolution so I may misunderstand its functionality and use it the wrong way. :o
I believe you intended to compare between avs.mt_convolution(clip, '1 2 1', '1 0 -1') and generic.Convolution(clip, [1, 2, 1, 0, 0, 0, -1, -2, -1], planes=0), which looks quite identical to me....
Chikuzen
4th January 2013, 07:04
hmm...
generic.Convolution always saturate the output on 8bit format.
mt_edge("1 2 1 0 0 0 -1 -2 -1 1", 0, 255) is same as mt_convolution("1 2 1", "1 0 -1", saturate=false)
currently, I'm working on imprementing Sobel and Prewitt proper function by the request from Myrsloik.
Since I'm not familiar with SIMD, I may require time for beginning it.
Chikuzen
4th January 2013, 18:29
Updated to 0.2.0
* Add new function 'Sobel'.
* Add new function 'Prewitt'.
* Convolution/HV: add new option 'saturate'.
* Minimum/Maximum: add new option 'coordinates'
* various bug fix.
Revgen
4th January 2013, 21:23
The coordinates option and saturate option fix the issues HolyWu described. Thank You.
Chikuzen
5th January 2013, 11:46
But the output of generic.Sobel/generic.Prewitt is quite different from the equivalent mode of mt_edge.
from masktools2 docs
"sobel" uses the kernel "0 -1 0 -1 0 1 0 1 0"
I've never heard calling this "Sobel" except masktools.
"hprewitt" is equivalent to : mt_logic(mt_edge("1 2 1 0 0 0 -1 -2 -1 1"), mt_edge("1 0 -1 2 0 -2 1 0 -1 1"), mode = "max"),
hprewitt? I think this is Sobel (http://en.wikipedia.org/wiki/Sobel_operator)
and, Prewitt that I wrote is 'Prewitt compass edge detection' which requires 8 kernels.
Myrsloik
5th January 2013, 12:20
from masktools2 docs
I've never heard calling this "Sobel" except masktools.
hprewitt? I think this is Sobel (http://en.wikipedia.org/wiki/Sobel_operator)
and, Prewitt that I wrote is 'Prewitt compass edge detection' which requires 8 kernels.
Now you made me go check the reference literature...
Sobel is indeed defined as 1 2 1, 0 0 0, - 1 -2 - 1 and then the horizontal and vertical filters are usually summed up as sqrt(sh^2+sv^2) or abs(sh) + abs(sv) for speed. There are also variants where the filter is rotated when looking for diagonal edges but I've never seen it used.
Now on to prewitt. Apparently the prewitt guy was busy and suggested several similar things. But the one you want is described here: http://en.wikipedia.org/wiki/Prewitt_operator
and should be just about identical to sobel except that it's 1 1 1.
I really can't find any mention of masktool's so called sobel filter. I can however tell you this, it really is implemented like a single 0 1 0, 1 0 -1, 0 -1 0 convolution and I think it looks like a horrible idea. It's easy to see that edges get a VEEEEEERY different weight depending on directionality. Just imagine a diagonal gradient in the \ and / directions and see the difference in result.
Chikuzen
5th January 2013, 12:52
I found some typo and wrong understanding on Sobel and Prewitt.
updated to 0.2.1
* Sobel/Prewitt: fix invalid logic
* Sobel/Prewitt: Change default values of 'min' and 'max'
aegisofrime
5th January 2013, 16:25
So is there an updated version of QTGMC implementing these generic filters yet?
Revgen
5th January 2013, 17:07
^Not yet.
The current Vapoursynth QTGMC script is here. http://forum.doom9.org/showthread.php?t=166582
Chikuzen
6th January 2013, 07:59
updated to 0.2.2
* Sobel, Prewitt: add new option 'rshift'
* Sobel, Prewitt: fix 9/10/16bit format processing
Are_
6th January 2013, 15:28
Link to 0.2.2 does not work.
Chikuzen
6th January 2013, 17:09
Link to 0.2.2 does not work.
fixed
Chikuzen
11th January 2013, 18:02
updated to 0.3.0
* add new function 'Blur'
kolak
11th January 2013, 20:31
:thanks:
kolak
16th January 2013, 17:04
Looks like there is a bug in blur when format is 16bit- footage has some green artefacts (10bit and 8bit are ok).
Chikuzen
16th January 2013, 22:20
(Probably,) fixed.
genericfilters_0.4.1.dll (http://www.mediafire.com/download.php?m4w138a7m3xdxyy)
kolak
16th January 2013, 23:26
Yes- seams to be fine. Thanks.
Could someone port yadifmod (eedi3+nnedi3 are already there)? QTGMC won't come any soon, so at least we could have this for now.
AVS dll works, but only in yv12 mode and overall processing is 2x slower then in avs.
Chikuzen
2nd August 2013, 19:15
update to 0.4.2
@HolyWu
probabry fixed.
mastrboy
3rd August 2013, 20:07
What is the substitute to mt_merge?
Myrsloik
3rd August 2013, 20:11
What is the substitute to mt_merge?
MaskedMerge() which is a part of the core.
mastrboy
3rd August 2013, 20:24
MaskedMerge() which is a part of the core.
Ah, no wonder i didn't see it in the function list in the first post in this thread... Thanks...
Chikuzen
6th August 2013, 08:17
update to 0.5.0
* add new function 'Hysteresis'
* Convolution: increase maximum matrix length from 5 to 17 when mode is 'h' or 'v'
* various bug fix.
OFF TOPIC:
BTW, I referd to Masktools-v1's code first and wrote an avisynth2.6 plugin first, in order to understand the algorithm of hysteresis mask.
http://pastebin.com/37gPmkNy
It seems that this filter is faster than masktools2a48 about 150% to 300% on my machine :eek:
(Probably, since the lump of superfluous flesh called STL was eliminated from the critical part.)
jackoneill
6th August 2013, 12:28
@Chikuzen: What do you think about adding the edge mask algorithms from tedgemask?
Chikuzen
6th August 2013, 13:55
@Chikuzen: What do you think about adding the edge mask algorithms from tedgemask?
I've never read the code of TEdgeMask.
if it's possivel , i'll write.
cretindesalpes
6th August 2013, 15:55
IIRC mt_edge("prewitt") does a pretty similar but slightly better job than TEdgeMask. This can be noticed on very faint lines. Maybe just a different rounding behaviour. I don't know which one is the fastest.
mandarinka
6th August 2013, 19:49
Tedgemask's default thresh is fairly high (conservative). You need to set threshy to like 4 (well, from the anime dvd I am trying now, it seems the equivalent is between 3 and 4) if you want sensitivity of "mt_edge("prewitt")", it seems to me. Ofc, with that sensitivity, both pick up a lot of false positive pixels.
Hard to say (and I am lazy to check this too much), but I like tedgemask more I think.
Chikuzen
9th August 2013, 14:51
I wrote TEMmod to understand how TEdgeMask works.
http://forum.doom9.org/showthread.php?t=168390
Now, I'm going to drop type1 and type2 when I port this to VS since it seems that there is no difference not much.
Any suggestions?
Chikuzen
12th August 2013, 12:39
update to 0.6.0
* add new function 'TEdge'
mastrboy
12th August 2013, 15:15
update to 0.6.0
* add new function 'TEdge'
Thanks...
That would be the same as this for vapoursynth: http://forum.doom9.org/showthread.php?t=168390 ?
Any chance you're going to add tcanny mask as well?
Would be great to see most of the masking tools/algorithms collected into 1 plugin.
sl1pkn07
12th August 2013, 18:04
fail build. missing convolution_utils.h
greetings
Chikuzen
13th August 2013, 03:28
fail build. missing convolution_utils.h
greetings
fixed
sl1pkn07
13th August 2013, 13:53
thanks
Reel.Deel
18th August 2013, 02:56
Out of curiosity (and learning purposes) how would one implement the "undot6" plugin talked about here (http://mechaweaponsvidya.wordpress.com/2013/01/)?
Chikuzen
21st August 2013, 03:23
update to 0.7.0
* add new funtion 'GBlur'
* add new function 'Canny'
Chikuzen
6th September 2013, 07:55
Hi Chikuzen,
May I know do you plan to add 'mode' to generic.Canny like AviSynth version has(people use mostly mode=1 IMHO)? :thanks:
no.
I don't know the reason why people use Canny to get an edge mask instead of Sobel.
Myrsloik
7th December 2013, 12:49
Forked source with fixes is available from:
https://github.com/myrsloik/GenericFilters
Fixed windows binaries are bundled with the R22 (and later) VapourSynth installer.
Mystery Keeper
10th February 2014, 13:30
VirtualDub crashed on Canny.
canny = core.generic.Canny(z)
Crash report. (http://paste.org.ru/?75mhif)
Myrsloik
11th February 2014, 15:03
VirtualDub crashed on Canny.
canny = core.generic.Canny(z)
Crash report. (http://paste.org.ru/?75mhif)
Was that with the version included in the VS installer?
What was the format and bitdepth of the input to canny?
Mystery Keeper
11th February 2014, 17:46
It was. Format is common YV12. Right after decoding d2v project.
Mystery Keeper
17th February 2014, 12:54
Canny gives me 3 masks, one for each plane. How can I mix them all in one plane?
Myrsloik
17th February 2014, 12:57
Canny gives me 3 masks, one for each plane. How can I mix them all in one plane?
Either use two Lut2 to get the max/sum of the masks (depending on preference) or simply only use the luma mask for everything. Personally I'd only use the luma mask and be done with it...
Mystery Keeper
17th February 2014, 13:12
Tried looking at separate planes. Guess you're right.
mawen1250
25th February 2015, 08:48
There's 1 pixel up-shift in each plane while comparing the result of generic.Canny(chroma=True) with that of tcanny(plane=7)/TCannyMod(chroma=1).
Myrsloik
25th February 2015, 09:16
There's 1 pixel up-shift in each plane while comparing the result of generic.Canny(chroma=True) with that of tcanny(plane=7)/TCannyMod(chroma=True).
I'll take a look at it when I have time again. Are you sure it isn't tcanny that shifts it?
mawen1250
25th February 2015, 09:49
I made a simple test pattern and confirm that the result of generic.Canny is wrong.
Myrsloik
27th March 2015, 20:10
I made a simple test pattern and confirm that the result of generic.Canny is wrong.
Here's a possibly fixed 32 bit dll (https://www.dropbox.com/s/wd6cum67qrtb70q/GenericFilters.dll?dl=1). Not tested but probably working.
Should fix the canny line shift and several problems in the minimum/maximum filters as well. Report your findings. Don't forget to delete the dll that comes with VapourSynth.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.