Skip to content

Commit

Permalink
Update scale_value range for masks and fix inner_hat
Browse files Browse the repository at this point in the history
  • Loading branch information
emotion3459 committed Nov 11, 2024
1 parent 9f1c688 commit b33975d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions vsmasktools/edge_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def luma_mask(clip: vs.VideoNode, thr_lo: float, thr_hi: float, invert: bool = T
lo, hi = (peak, 0) if invert else (0, peak)
inv_pre, inv_post = (peak, '-') if invert else ('', '')

thr_lo = scale_value(thr_lo, 32, clip, range_out=ColorRange.FULL)
thr_hi = scale_value(thr_hi, 32, clip, range_out=ColorRange.FULL)
thr_lo = scale_value(thr_lo, 32, clip)
thr_hi = scale_value(thr_hi, 32, clip)

return norm_expr(
get_y(clip),
Expand Down Expand Up @@ -135,7 +135,7 @@ def _prefilter(self, clip: vs.VideoNode, **kwargs: Any) -> vs.VideoNode:
if self is self.CLAHE: # type: ignore
limit, tile = kwargs.get('limit', 0.0305), kwargs.get('tile', 5)

return depth(depth(clip, 16).ehist.CLAHE(scale_value(limit, 32, 16, range_out=ColorRange.FULL), tile), clip)
return depth(depth(clip, 16).ehist.CLAHE(scale_value(limit, 32, 16), tile), clip)

return clip

Expand Down
2 changes: 1 addition & 1 deletion vsmasktools/hardsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def _mask(self, clip: vs.VideoNode, ref: vs.VideoNode, **kwargs: Any) -> vs.Vide
for x in (clip, ref)
)

highpass = scale_value(self.highpass, 32, clip, range_out=ColorRange.FULL)
highpass = scale_value(self.highpass, 32, clip)

mask = norm_expr(
[clipedge, refedge], f'x y - {highpass} < 0 {ExprToken.RangeMax} ?'
Expand Down
12 changes: 6 additions & 6 deletions vsmasktools/morpho.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from vsrgtools.util import wmean_matrix
from vstools import (
ConvMode, CustomIndexError, FuncExceptT, PlanesT, StrList, check_variable, copy_signature, core, fallback,
ColorRange, inject_self, interleave_arr, iterate, scale_value, to_arr, vs
inject_self, interleave_arr, iterate, scale_value, to_arr, vs
)

from .types import Coordinates, MorphoFunc, XxpandMode
Expand Down Expand Up @@ -112,7 +112,7 @@ def _morpho_xx_imum(
matrix = ExprList(interleave_arr(matrix, op * matrix.mlength, 2))

if thr is not None:
matrix.append('x', scale_value(thr, 32, src, range_out=ColorRange.FULL), ExprOp.SUB, ExprOp.MAX)
matrix.append('x', scale_value(thr, 32, src), ExprOp.SUB, ExprOp.MAX)

if multiply is not None:
matrix.append(multiply, ExprOp.MUL)
Expand Down Expand Up @@ -150,7 +150,7 @@ def _mm_func(

if not self._fast:
if thr is not None:
kwargs.update(threshold=scale_value(thr, 32, src, range_out=ColorRange.FULL))
kwargs.update(threshold=scale_value(thr, 32, src))

if multiply is not None:
orig_mm_func = mm_func
Expand Down Expand Up @@ -211,7 +211,7 @@ def _xxflate(
expr.append('x', ExprOp.MAX if inflate else ExprOp.MIN)

if thr is not None:
thr = scale_value(thr, 32, src, range_out=ColorRange.FULL)
thr = scale_value(thr, 32, src)
limit = ['x', thr, ExprOp.ADD] if inflate else ['x', thr, ExprOp.SUB, ExprToken.RangeMin, ExprOp.MAX]

expr.append(limit, ExprOp.MIN if inflate else ExprOp.MAX)
Expand Down Expand Up @@ -365,7 +365,7 @@ def inner_hat(

eroded = self.erosion(src, radius, planes, thr, coords, multiply, func=func, **kwargs)

return norm_expr([eroded, src], 'x y -', planes)
return norm_expr([src, eroded], 'x y -', planes)

@inject_self
def binarize(
Expand All @@ -375,7 +375,7 @@ def binarize(
) -> vs.VideoNode:
midthr, lowval, highval = (
thr and list(
scale_value(t, 32, src, range_out=ColorRange.FULL)
scale_value(t, 32, src)
for i, t in enumerate(to_arr(thr))
) for thr in (midthr, lowval, highval)
)
Expand Down
6 changes: 3 additions & 3 deletions vsmasktools/spat_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def flat_mask(src: vs.VideoNode, radius: int = 5, thr: float = 0.011, gauss: boo

blur = gauss_blur(luma, radius * 0.361083333) if gauss else box_blur(luma, radius)

mask = depth(luma, 8).abrz.AdaptiveBinarize(depth(blur, 8), scale_value(thr, 32, 8, range_out=ColorRange.FULL))
mask = depth(luma, 8).abrz.AdaptiveBinarize(depth(blur, 8), scale_value(thr, 32, 8))

return depth(mask, luma, dither_type=DitherType.NONE, range_in=ColorRange.FULL, range_out=ColorRange.FULL)

Expand All @@ -161,8 +161,8 @@ def texture_mask(
points: list[tuple[bool, float]] = [(False, 1.75), (True, 2.5), (True, 5), (False, 10)]
) -> vs.VideoNode:
levels = [x for x, _ in points]
_points = [scale_value(x, 8, clip, ColorRange.FULL, ColorRange.FULL) for _, x in points]
thr = scale_value(thr, 8, 32, ColorRange.FULL, ColorRange.FULL)
_points = [scale_value(x, 8, clip) for _, x in points]
thr = scale_value(thr, 8, 32, ColorRange.FULL)

qm, peak = len(points), get_peak_value(clip)

Expand Down

0 comments on commit b33975d

Please sign in to comment.