Log in

View Full Version : How do you get masking working?


RedDwarf1
6th August 2007, 22:33
Does anyone know if it is possible to change the colour of a section of video (which is yv12), reducing one colour component in just a small section of the video? Maybe using a mask?
The section looks like it was originally applied onto the video using an alpha channel. I think removing the graphic which was placed in ( which is a box) would be difficult and is not that noticeable except for the colour so reducing one colour component would reduce it's visibility to an acceptable level.

How would the mask need to be made, what colours for which section such as the area to be altered and the surrounding screen?
Can any Avisynth wizards make any suggestions on how to do this?

Mug Funky
7th August 2007, 00:22
i was working on a script for (more or less) just this a few weeks ago, but got distracted.

bascially you'll want to make a soft chroma key, then adjust the clip under it. it's a snip in a telecine suite, but in avisynth it's a tad tricky (though very possible).

depending on how much time i get today i might take another stab at it. in the meantime there's probably some useful scripts floating around that might help

Wilbert
7th August 2007, 20:23
http://avisynth.org/mediawiki/Tweak (last two examples)

RedDwarf1
8th August 2007, 06:06
Okay Wilbert I will look at that.

I need to mask the area so I can do what is needed. Here is the script I have tried but it only returns the full video and not the area that I wanted. I have converted to rgb32 as I was expecting to use RGBAjust to change the colour of the area. Can anyone see any mistakes in this for why it is not doing what I intended? I intended to remove just an area from the video using a mask, the mask has a white area surrounded by black. The white area is the area that I wanted to extract.

fullvid=MPEG2Source("F:\video\Video.demuxed.d2v", idct=2, cpu=0)
vidsegment=trim(fullvid,875,893).converttorgb32
vidsegment=resetmask(vidsegment)
vidmask=ImageSource("F:\video\area_mask.bmp").converttorgb32 #white pixels in mask are the area to keep, black ones are lost
thearea=mask( vidsegment, vidmask)
return thearea

RedDwarf1
9th August 2007, 00:20
Does masking work in this way? What use is masking if it does not work?

I must be getting something wrong but I have checked everything over and over but cannot see a problem with it.

What colour format does masking work in?

What am I missing? Some help would be appreciated.

Wilbert
9th August 2007, 20:39
1) check whether your mask is indeed correct:

mask = showalpha(thearea)
return mask

2) apply your clip and mask (as defined above) to Overlay. Have a look at the examples in the Overlay documentation.

RedDwarf1
11th August 2007, 21:32
Thanks that has got the part cut out.
What you wrote
mask = showalpha(thearea)
return mask

results in a totally black screen with a white area in the area that I want to alter the colour. I thought that mask() was enough to mask the area wanted.

I swapped the mask for an inverted mask that I made and when I used layer it has extracted the area I wanted.

The only trouble now is putting them back together as I have two clips, one with the original video without the rectangular region in it, that area is white and the second clip is the rectangular region of the area I wanted but outside that area is white. Putting them back together does not result in a good looking video as the white is causing problems with the video. If the white was black then it would of been much easier.

Do you know how I could put it back together?

Wilbert
11th August 2007, 23:41
Do you know how I could put it back together?
Probably :) Could you upload a short clip and your bmp somewhere? That talks a bit easier.