View Full Version : Creating a mask on video edge/border independent on video content?
mastrboy
25th February 2012, 17:42
I'm trying to create a 2px wide mask on left and right edge of the video.
My current solution is the following:
orig = last
cropped = crop(2,0,-2,0).AddBorders(2, 0, 2, 0, color=$000000)
border_mask = mt_edge(mt_makediff(orig,cropped)).mt_expand()
My solution has two defects which i have noticed already, if the video also has some pixels at $000000 "color" the mask will ignore those. The second on is that i have to add a mt_expand() for the mask to get to the edge and using mt_expand, the mask exceeds 2px in width.
Any better solutions for this?
Bloax
25th February 2012, 18:00
Wouldn't
orig=last
mskblank=BlankClip(Orig,Width=Orig.Width()-4)
msk=mskblank.AddBorders(2,0,2,0,color=$ffffff)
Be what you're looking for? (Unless I mugged up the BlankClip() options, it ought to be.)
Didée
25th February 2012, 18:05
x1 = orig.width()
x2 = string(x1)
border_mask = orig.mt_lutspa(relative=false,expr="x 2 < x "+x2+" 3 - > | 255 0 ?")
Edit -
Construction via addborders is of course possible. But IIRC the "color" option of Addborders always assumes RGB / YUY(TVlevels) range ... i.e. with color=$ffffff you get Y=235, not 255 (and vice versa Y=16 for color=$000000).
BlankClip has the two different options "color" and "color_yuv" to assign the desired color, but AddBorders hasn't.
mastrboy
25th February 2012, 18:11
Thanks guys :)
Both answers produced exactly what is was looking for. I'll do some speed tests and use the fastest one, though i don't think there would be much difference.
(Didee, i knew that some kind of mt_lut* would be able to do this, but i had no idea how to produce the code for it.)
Bloax
25th February 2012, 18:15
They're both "stupendously" fast.
But if we're talking about pure mask generation performance, the former spits out 3265 640x480 frames out in under a second, whilst the latter spits them out @ around 400 FPS according to AVSMeter.
And I guess $000000 would be the bottom of TVLevels then? (15, or was it 16?)
So yeah, sucks. (Well, unless a 7.815% difference doesn't bother you.) :V
mastrboy
25th February 2012, 18:20
Hehe, that is "stupendously" fast, the mask will be part of a larger filter chain so the one that steals the least CPU cycles will leave more processing power to the other filters...
Out of curiosity, what is the reason for 3 pixels on the right in the: mt_lutspa(relative=false,expr="x 2 < x "+x2+" 3 - > | 255 0 ?"), should it not be mt_lutspa(relative=false,expr="x 2 < x "+x2+" 2 - > | 255 0 ?") ?
Didée
25th February 2012, 18:46
If the video is 600 pixels wide, the position numbering goes from 0 to 599. You could set "x2 = string(x1-1)", or you could set "2 - >=" instead of "3 - >" in the lut.
Edit -
Not absolutely sure, but doesn't lutspa do its thing on every video frame again and again? Try to follow up with
border_mask = border_mask.trim(1,1).loop(framecount(orig))
so that the mask is created only for one frame, and for all other frames, it's simply pulled from the cache.
mastrboy
25th February 2012, 19:18
If the video is 600 pixels wide, the position numbering goes from 0 to 599. You could set "x2 = string(x1-1)", or you could set "2 - >=" instead of "3 - >" in the lut.
Edit -
Not absolutely sure, but doesn't lutspa do its thing on every video frame again and again? Try to follow up with
border_mask = border_mask.trim(1,1).loop(framecount(orig))
so that the mask is created only for one frame, and for all other frames, it's simply pulled from the cache.
I see (i think).
That is a pretty elegant solution about the caching, instead of recreating the mask pr frame, since it will always be equal, just create it once and use from cache :cool:
Leinad4Mind
4th July 2012, 18:01
Hi there, I want to create a mask to apply some filters, just on all borders. Left, right, up and down.
The same pixels that Crop(4,4,-4,-4) will removed, I wanna filter them. And I need a mask to just apply to that zone.
I've tried with this, but without sucess :/ (it only masks the 4 pixels down)
orig=last
orig2=last.Levels(85, 0.01, 220, 0, 255) #This levels is just to see where the mask is applied
x1 = orig.width()
x2 = string(x1-4)
y1 = orig.height()
y2 = string(y1-4)
border_mask = orig.mt_lutspa(relative=false,expr="x 2 < x "+x2+" 3 - > y 2 < y "+y2+" 3 - > | 255 0 ?")
mt_merge(orig,orig2,border_mask, sse4=true)
What is the correct expression?! :confused:
Gavino
4th July 2012, 18:20
..., expr = "x 4 < x "+x2+" >= y 4 < y "+y2+" >= | | | 255 0 ?"
Didée
4th July 2012, 18:21
expr="x 4 < x "+x2+" >= y 4 < y "+y2+" >= | | | 255 0 ?"
edit: Wee, in editor view the code looks quite confusing, with all those color tags.
edit: Hrmpf. Two edits to arrive at what Gavino posted in the first run.
Gavino
4th July 2012, 18:27
Didée, you got there in the end. :D
Didée
4th July 2012, 18:33
Slowly. You missed my third edit of the first edit, and my fifth edit of the 2nd edit. :D
Leinad4Mind
4th July 2012, 19:02
Thanks! :cool:
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.