Skip to content

Commit b9936d1

Browse files
committed
RB: Add prefilter param for linemasks
1 parent 13d2213 commit b9936d1

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

vodesfunc/rescale.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
FieldBasedLike,
55
FrameRangesN,
66
FunctionUtil,
7-
GenericVSFunction,
7+
VSFunctionNoArgs,
88
core,
99
get_video_format,
1010
limiter,
@@ -16,6 +16,7 @@
1616
from vsmasktools import Morpho, XxpandMode
1717
from vsexprtools import norm_expr
1818
from vsrgtools import remove_grain
19+
from vsdenoise import prefilter_to_full_range
1920
from vsscale import ArtCNN
2021
from typing import Self
2122
import inspect
@@ -107,7 +108,7 @@ def descale(
107108

108109
return self
109110

110-
def post_descale(self, func: GenericVSFunction | list[GenericVSFunction]) -> Self:
111+
def post_descale(self, func: VSFunctionNoArgs | list[VSFunctionNoArgs]) -> Self:
111112
"""
112113
A function to apply any arbitrary function on the descaled clip.\n
113114
I can't think of a good usecase/example for this but I was asked to add this before.
@@ -134,6 +135,7 @@ def linemask(
134135
inflate_iter: int = 0,
135136
expand: int | tuple[int, int | None] = 0,
136137
kernel_window: int | None = None,
138+
prefilter: bool | VSFunctionNoArgs = False,
137139
**kwargs,
138140
) -> Self:
139141
"""
@@ -146,6 +148,8 @@ def linemask(
146148
:param expand: Apply an ellipse morpho expand with the passed amount.
147149
Can be a tuple of (horizontal, vertical) or a single value for both.
148150
:param kernel_window: To override kernel radius used in case of border_handling being used.
151+
:param prefilter: Prefilter the input clip for the mask function.\n
152+
`True` will call `prefilter_to_full_range`. `False` to disable.
149153
:param **kwargs: Any other params to pass to the edgemask creation. For example `lthr` or `hthr`.
150154
"""
151155
if self.upscaled:
@@ -156,12 +160,17 @@ def linemask(
156160
edgemaskFunc = EdgeDetect.ensure_obj(mask or Kirsch())
157161

158162
# Perform on doubled clip if exists and downscale
163+
164+
wclip = self.doubled if self.doubled else self.funcutil.work_clip
165+
if prefilter:
166+
wclip = prefilter_to_full_range(wclip) if not callable(prefilter) else prefilter(wclip)
167+
159168
if self.doubled:
160-
scaler = Bilinear.ensure_obj(downscaler)
161-
self.linemask_clip = edgemaskFunc.edgemask(self.doubled, **kwargs)
169+
scaler = Scaler.ensure_obj(downscaler or Bilinear())
170+
self.linemask_clip = edgemaskFunc.edgemask(wclip, **kwargs)
162171
self.linemask_clip = scaler.scale(self.linemask_clip, self.funcutil.work_clip.width, self.funcutil.work_clip.height, **self.post_crop)
163172
else:
164-
self.linemask_clip = edgemaskFunc.edgemask(self.funcutil.work_clip, **kwargs)
173+
self.linemask_clip = edgemaskFunc.edgemask(wclip, **kwargs)
165174

166175
self.linemask_clip = self._process_mask(self.linemask_clip, maximum_iter, inflate_iter, expand)
167176

@@ -233,7 +242,7 @@ def double(self, upscaler: ScalerLike = ArtCNN.R8F64) -> Self:
233242
self.doubled = scaler.supersample(self.descaled)
234243
return self
235244

236-
def post_double(self, func: GenericVSFunction | list[GenericVSFunction]) -> Self:
245+
def post_double(self, func: VSFunctionNoArgs | list[VSFunctionNoArgs]) -> Self:
237246
"""
238247
A function to apply any arbitrary function on the doubled clip.
239248

0 commit comments

Comments
 (0)