View Full Version : Masktools 2.0 example
MadRat
6th February 2008, 01:07
As I was looking through one of my videos last week I noticed a part of the video had bad color banding in just one area. I thought back on all the times I’d had a specific area of the video where I’d wished I could apply a filter leave the rest unfiltered. One of my encoding friends mentioned that masktools could do exactly that, but he didn’t know exactly how. I’ve tried to understand the masktools 2.0 documentation but so far I can’t. I could really use a good example.
So imagine for a moment that I have the following hypothetical situation: I have file named “E:\My Videos\needs_circular_filtering.avi” that I want to apply gradfun2db() to a circular area at 320 by 200 with a radius of 100. What would my avisynth file look like?
martino
8th February 2008, 20:28
Since nobody has replied... I'll at least try to breathe in some life into this thread, albeit it might not be useful at all but might spark some more replies.
I'm not personally aware of any AviSynth commands that could take out a circular shape and filter just that out (but with some smart usage of Crop and Overlay you can get a rectangular shape), or filter a whole picture and then cut out the circular section and overlay on top of the original clip or whatever that you need. Not sure about masktools either...
This is only hypothetical (and as well as a question to the ones who might know more); Would it not be possible to manually create a circular mask, in photoshop or some other picture editing application, and then use that as a mask for what should be merged from the filtered clip to the original one and what shouldn't, as one can do similarly with mt_edge/mt_motion and mt_merge?
MadRat
9th February 2008, 01:15
Thank you martino, for replying to my question. I decided to ask specifically about a circular shape because I knew I could use crop and overlay to get a square or rectangular shape.
I gave myself 50/50 odds that someone would say, "No you can't do that with masktools. Masktools can only be used like this..." and give an explanation. But after 131 views no one did. What genuinely consernes me is the question, does anyone really know how to use masktools 2?
martino
9th February 2008, 14:56
Oh well, here I tried something...
Circular Mask (http://i118.photobucket.com/albums/o117/martino2k6/encoding/circular_mask.png)
This was created with GIMP, background colour was (in hex/html) #008800 and the circular mask was #4AFF14 and for a frame size of 704x400.
Script:
AVISource("some video")
ConvertToYV12() #if required
mainclip = last
filtered = gradfun2db()
mask = ImageReader("circular_mask.png",0,mainclip.framecount,mainclip.framerate).ConvertToYV12().mt_binarize()
mt_merge(last,filtered,mask)
This worked for me. Set gradfun2db to high thresholds to see better that it works if you're not convinced yourself from the defaults. That mask probably isn't good for you, but at least now you know that it can be done, and should know how to do a one that you need yourself.
Wilbert
9th February 2008, 15:22
Since nobody has replied... I'll at least try to breathe in some life into this thread, albeit it might not be useful at all but might spark some more replies.
I'm not personally aware of any AviSynth commands that could take out a circular shape and filter just that out (but with some smart usage of Crop and Overlay you can get a rectangular shape), or filter a whole picture and then cut out the circular section and overlay on top of the original clip or whatever that you need. Not sure about masktools either...
Try GraMaMa (a gradient mask maker): http://forum.doom9.org/showthread.php?p=598958#post598958 for creating circular masks.
Didée
9th February 2008, 16:25
My first thought was GraMaMa too, but ... can you get a *solid* circle from it? Doesn't it always create a gradient over the given radius?
The easiest way to get masks of a given shape is indeed to manually create a fitting bitmap, and read it with ImageReader. MaskTools is great for manipulation, but not for creating a certain shape out of thin air. Producing a simple circle becomes an effort:
white = blankclip(width=16,height=16,color=$FFFFFF,pixel_type="yv12")
pixel = white.addborders(0,0,15*16,15*16).pointresize(16,16)
pixel.addborders(128,128,128-16,128-16).mt_binarize()
mt_luts(last,last,mode="max",pixels=mt_circle(80,true),yexpr="y")
mt_inflate().mt_deflate()
greyscale()
Wilbert
9th February 2008, 17:17
My first thought was GraMaMa too, but ... can you get a *solid* circle from it? Doesn't it always create a gradient over the given radius?
You need to use levels afterwards, or modify the source of GraMaMa.
MadRat
17th February 2008, 01:08
As he hinted above, Wilbert managed to modify the source of GraMaMa so it would produce shapes without gradients.
Thread: http://forum.doom9.org/showthread.php?t=134869
Wilbert's page: http://www.wilbertdijkhof.com/
Download link: http://www.wilbertdijkhof.com/GraMaMa_v02.zip
I spent most of the day trying to figure out how to use it when a friend of mine (Skyward) took a look at it and had a working script in 10 minutes, like he always does. :rolleyes:
AVISource("E:\My Videos\needs_circular_filtering.avi")
source = last
grey = source.GreyScale()
alphamask = source.BlankClip(color=$FFFFFF).GraMaMa(1, 320, 240, 120, binarize=true).Invert()
Overlay(grey,mask=alphamask,mode="blend")
Congratulations to Masktools genius Didée, coding genius Wilbert and avisynth scripting genius Skyward. By changing GreyScale() to a period separated filter chain anyone will be able to do a quick and dirty application of specific filters to specific areas of any video. :thanks:
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.