YRangeMask

From Avisynth wiki
Revision as of 19:02, 25 June 2020 by Reel.Deal (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Abstract
Author Chikuzen
Version 2016/01/24
Download mt_yrangemask.avsi
Category Masking
License
Discussion

Contents

Description

AviSynth script to create a mask by specifying the range of the brightness.
mt_yrangemask is a script implementation of the old YRangeMask plugin by Putin. The script version is much faster and supports additional colorspaces.

Requirements


Required Plugins

Latest versions of the following filters are recommended unless stated otherwise.


Syntax and Parameters

mt_yrangemask (clip , int "min_y", int "fade_min_y", int "max_y", int "fade_max_y", bool "invert")


clip   =
Input clip.


int  min_y = 0
Minimum threshold.


int  fade_min_y = 0
How many minimum pixels to fade.


int  max_y = 0
Maximum threshold.


int  fade_max_y = 0
How many maximum pixels to fade.


bool  invert = false
Set to true to invert the mask.


Script

function mt_yrangemask(clip clip, int "min_y", int "fade_min_y", int "max_y", int "fade_max_y", bool "invert")
{
    assert(clip.IsPlanar(), "clip is not planar format")
    min = default(min_y, 0)
    max = default(max_y, 0)
    assert(min >= 0 || min < 256 || max < 256, "Specify in the range from 0 to 255")
    assert(min <= max, "min_y must be less than or equal to max_y")
    fmin = default(fade_min_y, 0)
    fmax = default(fade_max_y, 0)
    assert((fmin + fmax) <= (max - min), "'fade_min_y + fade_max_y' should be less than or equal to 'max_y - min_y'")

    min = string(min - 1)
    max = string(max + 1)
    fmin = string(fmin + 1)
    fmax = string(fmax)
    invert = default(invert, false)

    #expr = 255 / (x < max - fmax ? fmin / (x - min) : (fmax + 1) / (max - x))
    #expr = invert ? 255 - expr : expr
    expr = "255 / (x < " + max  + " - " + fmax + " ? " + fmin + " / (x - " + min + ") : (" + fmax + " + 1) / (" + max + " - x))"
    expr = (invert ? "255 - " : "") + expr

    return clip.mt_lut(mt_polish(expr), chroma="0")
}


Examples

Masked areas and the effect of the fade parameters.
Note: illustration was taken from YRangeMask docs.
1) mt_yrangemask(min_y=16, fade_min_y=0, max_y=80, fade_max_y=0)
2) mt_yrangemask(min_y=16, fade_min_y=4, max_y=80, fade_max_y=16)

Yrangemask.png

Another example:

 BlankClip(length=10000, width=1920, height=1080, pixel_type="YV12")
 mt_lutspa(mode="relative", expr="x 256 *", chroma="128")

 mt_yrangemask(min_y=16, fade_min_y=4, max_y=80, fade_max_y=16, invert=true)


Changelog

Version      Date            Changes
2016/01/24 - mt_yrangemask: MaskTools2 script reimplementation by Chikuzen v0.03 2012/06/02 - ? v0.02 2012/05/28 - ? v0.01 2012/05/01 - initial release


Archived Downloads

  • Note: YRangeMask is an AviSynth 2.5 closed source plugin. Not recommended! The script implementation is faster and supports additional colorspaces.
Version Download
v0.03 yrangemask003.rar
v0.02 yrangemask002.rar


External Links




Back to External Filters

Personal tools