View Full Version : Use spots from one mask to select spots on another mask


nonoitall
31st July 2007, 07:01
This is kind of an obscure question, but I have my reasons for asking it. :) It's easier to show you what I want to do than explain it, so here goes:

Suppose you have this mask (A):
http://forum.doom9.org/attachment.php?attachmentid=7478&stc=1&d=1185861326
And this mask (B):
http://forum.doom9.org/attachment.php?attachmentid=7480&stc=1&d=1185861326
From those masks, I need a function that can create this result:
http://forum.doom9.org/attachment.php?attachmentid=7479&stc=1&d=1185861326

Basically, if any contiguous region of non-black pixels on mask A is overlapped at any point by non-black pixels on mask B, that whole region from mask A should be present in the result. Know of any way to do this? Thanks in advance!

Zarxrax
31st July 2007, 12:36
Wow... thats a pretty complicated thing you wanna do. I'm pretty sure its not possible with avisynth, short of writing your own custom plugin to do it.

Manao
31st July 2007, 18:08
mt_hysteresis does exactly that. Follow my signature

Zarxrax
31st July 2007, 20:49
Well, I stand corrected :p

Manao
31st July 2007, 21:03
Well, I don't know anybody else aside from me that has used that filter, so you can say I did write my own custom plugin :)

nonoitall
31st July 2007, 23:02
Wow I'm surprised anyone else had use for such a function! I had read through MaskTools' documentation before, but never quite understood what mt_hysteresis did. Anyway, I went to try it out, but ran into a bit of a problem. Here's a sample script:
LoadPlugin("mt_masktools.dll")

big = ImageSource("maskA.bmp").ConvertToYV12()
small = ImageSource("maskB.bmp").ConvertToYV12()

return mt_hysteresis(small, big)
Opening the script in VDubMod crashed VDubMod ("VirtualDub has encountered a problem...") and opening the script in Media Player Classic spat out this error message from AviSynth:
CAVIStreamSynth: System exception - Access violation at 0x0, reading from 0x0
This seems to happen with any script I add mt_hysteresis to, even if the script previously had used other MaskTools functions without problems. (That was with AviSynth 2.57.) I also tried the same script with AviSynth 2.56 and VDubMod and MPC both immediately closed when attempting to open the script (no error message or anything). Any idea what the problem could be?

EDIT: Also forgot to mention I'm using MaskTools 2.0a30. (The old version doesn't have a hysteresis function does it?)

Manao
1st August 2007, 05:33
I found the bug, I'll release a version tonight

nonoitall
1st August 2007, 07:19
Awesome, I really appreciate it!

:thanks:

Manao
1st August 2007, 21:03
Follow my sig ( again )

nonoitall
1st August 2007, 23:11
Hmm, no more crashing, but now I just get a 100% white mask. (Using the script from above.) I also tried using completely black masks as input, but still got a clip full of completely white frames. Am I doing something wrong? The "small" mask is supposed to select which parts of the "large" mask appear in the returned mask, right? Sorry if I'm being a pest!

Manao
2nd August 2007, 05:53
mt_hysteresis considers that a pixel is lit if its value isn't 0. I bet that after converttoyv12, the black pixel are at 16, not 0.

Add mt_lut(yexpr="x 40 < 0 255 ?",y=3,u=2,v=2) after each converttoyv12.

Furthermore, add(u=2,v=2) to the parameters of mt_hysteresis.

nonoitall
2nd August 2007, 06:07
I'd love to have things like that occur to me. :) That did the trick. If I knew you in person I would give you a cookie or something, but since I don't, thank you very much!