VideoHelp Forum
+ Reply to Thread
Results 1 to 10 of 10
Thread
  1. I am trying to only target the character's face. I am almost close to perfecting the mask, but I would like to bypass the whites of the character's eyes, and his outfit which is white-ish. Orange is just so you can see where I want to apply the filter. Attached is a sample of what I've been able to achieve with this script. Any help with adjusting would be greatly appreciated.

    Code:
    AVISource("blah.avi")
    a=last
    b=blankclip(a, color=color_orange)
    mask = mt_binarize(threshold=65, Levels(50, 0.6, 255, 16, 255). FastLineDarkenMOD(100). santiag())
    Overlay(a,b,mask=mask)
    Image Attached Thumbnails Click image for larger version

Name:	filteredsample.jpg
Views:	22
Size:	156.4 KB
ID:	60358  

    Quote Quote  
  2. Need original video clip. But simply using brightness isn't going to work.
    Quote Quote  
  3. simply using brightness isn't going to work.
    I figured as much. Hopefully I can incorporate a more suitable command line? I'll upload in a moment.
    Quote Quote  
  4. It is attached
    Image Attached Files
    Quote Quote  
  5. I came up with this:

    Code:
    AviSource("10038-10072.avi") 
    
    orange = BlankClip(last, color=color_orange)
    
    hsmask = MaskHS(StartHue=110, EndHue=130, MinSat=30, MaxSat=70).Spline36Resize(width, height).ConvertToYV12()
    
    bmask1 = mt_binarize(120)
    bmask2 = mt_binarize(145)
    bmask = Overlay(bmask1, bmask2, mode="subtract")
    
    fullmask = Overlay(hsmask, bmask, mode="multiply").Blur(1.0)
    
    Overlay(last, orange, mask=fullmask)
    MaskHS() is used to create a mask limited to the color of his face. To get enough of the shades the limits have to be pretty wide. So this mask selects some other parts of the picture too.

    mt_binarize is used to make a mask of only parts of the picture whose brightness is greater than 120, and another mask where the brightness is greater than 145. The latter is subtracted from the former to give a mask that is only parts of the picture with a brightness between 120 and 145.

    hsmask and bmask are then multiplied together. Since each pixel in the masks is either 0 or 255 this is equivalent to a logical AND: 0*0=0, 0*255=0, 255*0=0, 255*255=255. So the final masks is only pixels that are the right color AND the right intensity. The resulting mask is blurred a bit to soften the edges.

    Finally, the fullmask is used to overlay the orange color. A bit of that object at the left edge of the frame is colored too. Tweaking the thresholds might help with that.

    Image
    [Attachment 60371 - Click to enlarge]
    Quote Quote  
  6. Thank you. It all sounds good but why splineresize?
    Quote Quote  
  7. With YV12 video the U and V planes are half the size (each dimension) of the Y plane. So MaskHS delivers a 360x240 mask from the 720x480 frame. The mask must be brought back to the full frame size.
    Quote Quote  
  8. Ok, now I understand. I notice that as I change the values in mt_binarize, I can cover different areas as needed in different video scenes. This is pretty damn fantastic. Thanks jagabo, for your script and thorough explanation.

    I saved your script and explanations as comments on my script for future use.

    Is there a rule of thumb with value numbers, depending on colors? For example if I were to only want to filter blue, or red or just green
    Quote Quote  
  9. Originally Posted by Betelman View Post
    Is there a rule of thumb with value numbers, depending on colors? For example if I were to only want to filter blue, or red or just green
    If you look at the docs for MaskHS you'll see a chart for the primary colors.

    http://avisynth.nl/index.php/MaskHS

    Image
    [Attachment 60375 - Click to enlarge]


    Others colors you can estimate from the chart then experiment to you find what you need.

    And note, I gave you the tools to understand this before:

    https://forum.videohelp.com/threads/394036-using-masks-to-target-specific-colors/page2...hs#post2584960



    The colored boxes represent the UV vector map, the same as the maskhs diagram above, except the colors are shown within the graph rather than just a circle around the edges. U increases horizontally from left to right. V increases vertically from top to bottom. Saturation increases from the center to the edges. The mask generated from the indicated values is the black box/circle/wedge. That is, the mask was used to overlay black over the full color map.

    Hue and Saturation are the same as U and V, except HS is expressed in polar coordinates (angle, radius) rather than Cartesian coordinates (X,Y).

    https://en.wikipedia.org/wiki/Polar_coordinate_system
    https://en.wikipedia.org/wiki/Cartesian_coordinate_system
    Last edited by jagabo; 19th Aug 2021 at 18:55.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!