MaskHS

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(Examples)
(note AVS+ differences)
Line 1: Line 1:
Added in v2.6. Returns a mask (as [[Y8]]) of clip using a given hue and saturation range.
+
<div style="max-width:82em; min-width:42em;" >
 +
{{AvsStarFilter}}Returns a mask (as [[Y8]]) of clip using a given hue and saturation range. Added in v2.6.
 +
 
 +
{{AvsPluscon}} adds new [[#realcalc|{{FuncArg|realcalc}}]] parameter.
 +
 
 +
 
  
 
== Syntax and Parameters ==
 
== Syntax and Parameters ==
Line 5: Line 10:
 
{{FuncDef
 
{{FuncDef
 
|MaskHS(clip [, int ''startHue'', int ''endHue'', int ''maxSat'', int ''minSat'', bool ''coring'' ] )
 
|MaskHS(clip [, int ''startHue'', int ''endHue'', int ''maxSat'', int ''minSat'', bool ''coring'' ] )
 +
}}
 +
 +
{{FuncDef
 +
|MaskHS(clip [, int ''startHue'', int ''endHue'', int ''maxSat'', int ''minSat'', bool ''coring'',
 +
bool ''realcalc'' ] ){{AvsPluscon}}
 
}}
 
}}
  
Line 59: Line 69:
  
 
::Practically the saturation of a pixel will be in the range [0,100] (thus 0-100%), since these correspond to valid RGB pixels (100% corresponds to R=255, G=B=0, which has a saturation of 119). An overshoot (up to 150%) is allowed for non-valid RGB pixels (150% corresponds to U=V=255, which has a saturation of sqrt(127<sup>2</sup>+127<sup>2</sup>) = 180).  
 
::Practically the saturation of a pixel will be in the range [0,100] (thus 0-100%), since these correspond to valid RGB pixels (100% corresponds to R=255, G=B=0, which has a saturation of 119). An overshoot (up to 150%) is allowed for non-valid RGB pixels (150% corresponds to U=V=255, which has a saturation of sqrt(127<sup>2</sup>+127<sup>2</sup>) = 180).  
 +
::{{AvsPluscon}}[[TODO]] needs documentation of behavior at high bit depth.
  
 
::Range 0 to 150 (percent), default 150, 0; thus when using the default values all pixels will be processed.
 
::Range 0 to 150 (percent), default 150, 0; thus when using the default values all pixels will be processed.
  
 
:{{Par2|coring|bool|true}}
 
:{{Par2|coring|bool|true}}
::When set to true, the luma (Y) is clipped to [16,235]; when set to false, the luma is left untouched.
+
::When set to true, the luma (Y) is clipped to TV-range; when set to false, the luma is left untouched.
 +
 
 +
{{HiddenAnchor|realcalc}}
 +
:{{Par2|realcalc|bool|false{{AvsPluscon}} }}
 +
::When true, force 'no-lookup': pure float calculation of new pixel values (always true for certain high bit depths) ([[TODO]] - clarify)
 
</div>
 
</div>
  
Line 114: Line 129:
 
  | Initial Release
 
  | Initial Release
 
  |}
 
  |}
 +
</div>
  
 
[[Category:Internal_filters]]
 
[[Category:Internal_filters]]
 
[[Category:Masking]]
 
[[Category:Masking]]

Revision as of 02:57, 22 April 2017

Returns a mask (as Y8) of clip using a given hue and saturation range. Added in v2.6.

AVS+ adds new realcalc parameter.


Syntax and Parameters

MaskHS(clip [, int startHue, int endHue, int maxSat, int minSat, bool coring ] )

MaskHS(clip [, int startHue, int endHue, int maxSat, int minSat, bool coring, bool realcalc ] )AVS+

int  startHue = 0
int  endHue = 360
The resulting mask will contain source values in the range [startHue, endHue] when startHue<endHue. Note that the hue is periodic, thus a hue of 360 degrees corresponds with a hue of zero degrees.
If endHue<startHue then the range [endHue, 360] and [0, startHue] will be selected (thus anti-clockwise). If you need to select a range of [350, 370] for example, you need to specify startHue=370, endHue=350.
Range 0 to 360 (degrees), default 0, 360; thus when using the default values, all pixels will be processed.
The following shows some arbitrary startHue and endHue values for the basic colors, with a Histogram vectorscope to illustrate the color circle:
Color startHue (center) endHue
Labeled-vector-color2.png
Red 075 102 115
Yellow 150 176 180
Green 191 230 258
Cyan 279 282 300
Blue 316 000 004
Magenta 028 048 052
int  maxSat = 150
int  minSat = 0
The resulting mask will contain source values in the range [minSat, maxSat].
Practically the saturation of a pixel will be in the range [0,100] (thus 0-100%), since these correspond to valid RGB pixels (100% corresponds to R=255, G=B=0, which has a saturation of 119). An overshoot (up to 150%) is allowed for non-valid RGB pixels (150% corresponds to U=V=255, which has a saturation of sqrt(1272+1272) = 180).
AVS+TODO needs documentation of behavior at high bit depth.
Range 0 to 150 (percent), default 150, 0; thus when using the default values all pixels will be processed.
bool  coring = true
When set to true, the luma (Y) is clipped to TV-range; when set to false, the luma is left untouched.
bool  realcalc = falseAVS+
When true, force 'no-lookup': pure float calculation of new pixel values (always true for certain high bit depths) (TODO - clarify)


Examples

  • Suppose we want to create a mask of the skin of the girl below. The proper way to do this is to look at the vectorscope of Histogram:
clip = ...
Histogram(clip, mode="color2")
Tweak original2 plus hist.jpg
and estimate the hue range you want to select. As can be seen, the orange hue is between (about) 105 and 165 degrees.
Note: axis labels have been added to the vectorscope as a guide – they are not generated by the above script
Start with a wide hue range and narrow it until the output of MaskHS isolates the range of interest. You can also use Tweak to preview the affected range (with sat=0), as the arguments are compatible.
In our example we end at startHue=105, endHue=138, and the following mask is obtained:
clip = ...
MaskHS(startHue=105, endHue=138)
Maskhs.jpg


  • Looking at the blue screen example in Overlay the following can be used
testcard = ColorBars

# example subtitle file with blue background:
subs = ImageSource("F:\TestClips\blue.jpg").ConvertToYV24

# subs.Histogram(mode="color2").ConvertToRGB # blue in [345,359]
mask_hs = subs.MaskHS(startHue=340, endHue=359).Levels(0, 1, 255, 255, 0)

Overlay(testcard, subs, mask=mask_hs, mode="blend", opacity=1)

Changelog

v2.60 Initial Release
Personal tools