Manao
23rd November 2003, 20:34
Here is a part of the script I used to clean "The Beauty and the Beast". The version I got ( PAL, french ) presented a lot of ringing artifacts around edges, and was way too sharpened. I wanted to eliminate those artifacts without blurring the picture, and I may have succeeded.source = MPEG2Source("E:\Ripp\beauty.d2v",cpu2="xxxxoo").crop(16,16,-16,-16)
#make a filtered version of the source
blurclip = source.deen("a2d",2,10,12)
#make a edge's mask of the clip, only for luma
edgemask = source.edgemask(8,8,0,0,"sobel",Y=3,U=1,V=1) #(3)
#enlarge the radius of that mask seven times (1)
mask7 = edgemask.blur(0.5).blur(0.5).blur(0.5).blur(0.5).blur(0.5) /
.blur(0.5).blur(0.5).binarize(1,false,Y=3,U=-0,V=-0)
#create a clip with luma and chroma at zero (2)
greenclip = source.blankclip().coloryuv(cont_u = 0, off_u = -255,cont_v = 0, off_v = -255)
#create the final mask
mask = mask7.maskedmerge(greenclip,edgemask,Y=3,V=1,U=1)
#apply the filtering
result = source.maskedmerge(blurclip,edgemask,Y=3,V=2,U=2)
return resultSeveral notes have to be made :
- I used the MaskTools (http://cultact-server.novi.dk/kpo/avisynth/masktools-1.4.1.zip), which are a great tool, but are unfortunately buggy.
- This bugginess explains the (1) and (2) :
(1) : I wanted to enlarge the mask, which could have be done by using inflate() ( from the MaskTools package ), but it didn't work. So I had to use a mean filter (blur), several times, and binarize afterwards.
(2) : I wanted to substract the two mask, there is also a function in the masktools ( YV12Subtract ), but this one also didn't work, so I had to create a blankclip ( in YV12 space, so it isn't black, but darkgreen ), and use maskedmerge to make the difference between the two mask.
- My script may have some similarities with mf's one, but since I don't understand his script very well, I can't be sure
- I only filter the luma plane
- It works only in YV12
- The version of the MaskTools I use is different from the one used by mf in mfToon ( I least I think so, from what I read )
- To adapt my script to a previous version of the MaskTools ( the one used by mf, for example ), remplace line (3) by :edgemask = source.edgemask("sobel",Y=3,U=1,V=1).binarize(12,false,Y=3,U=-0,V=-0)It should work ( not tested though )
- You can see results here (http://jourdan.madism.org/~manao/index.html) ( The screenshots were made with a previous version of the script, but the quality is improved with this new script )
- The script is largely 'tweakable' ( different softening filters, different radius / threshold for the mask, and even the possibility to make different filtering with different radius )
- It's not too slow ( ~14 fps with a null test speed, on an Athlon XP 2000+ )
- It might work with movies but it isn't tested ( yet )
#make a filtered version of the source
blurclip = source.deen("a2d",2,10,12)
#make a edge's mask of the clip, only for luma
edgemask = source.edgemask(8,8,0,0,"sobel",Y=3,U=1,V=1) #(3)
#enlarge the radius of that mask seven times (1)
mask7 = edgemask.blur(0.5).blur(0.5).blur(0.5).blur(0.5).blur(0.5) /
.blur(0.5).blur(0.5).binarize(1,false,Y=3,U=-0,V=-0)
#create a clip with luma and chroma at zero (2)
greenclip = source.blankclip().coloryuv(cont_u = 0, off_u = -255,cont_v = 0, off_v = -255)
#create the final mask
mask = mask7.maskedmerge(greenclip,edgemask,Y=3,V=1,U=1)
#apply the filtering
result = source.maskedmerge(blurclip,edgemask,Y=3,V=2,U=2)
return resultSeveral notes have to be made :
- I used the MaskTools (http://cultact-server.novi.dk/kpo/avisynth/masktools-1.4.1.zip), which are a great tool, but are unfortunately buggy.
- This bugginess explains the (1) and (2) :
(1) : I wanted to enlarge the mask, which could have be done by using inflate() ( from the MaskTools package ), but it didn't work. So I had to use a mean filter (blur), several times, and binarize afterwards.
(2) : I wanted to substract the two mask, there is also a function in the masktools ( YV12Subtract ), but this one also didn't work, so I had to create a blankclip ( in YV12 space, so it isn't black, but darkgreen ), and use maskedmerge to make the difference between the two mask.
- My script may have some similarities with mf's one, but since I don't understand his script very well, I can't be sure
- I only filter the luma plane
- It works only in YV12
- The version of the MaskTools I use is different from the one used by mf in mfToon ( I least I think so, from what I read )
- To adapt my script to a previous version of the MaskTools ( the one used by mf, for example ), remplace line (3) by :edgemask = source.edgemask("sobel",Y=3,U=1,V=1).binarize(12,false,Y=3,U=-0,V=-0)It should work ( not tested though )
- You can see results here (http://jourdan.madism.org/~manao/index.html) ( The screenshots were made with a previous version of the script, but the quality is improved with this new script )
- The script is largely 'tweakable' ( different softening filters, different radius / threshold for the mask, and even the possibility to make different filtering with different radius )
- It's not too slow ( ~14 fps with a null test speed, on an Athlon XP 2000+ )
- It might work with movies but it isn't tested ( yet )