Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct value scaling and use scale_8bit where applicable #126

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vsdenoise/mvtools/mvtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ColorRange, ConstantFormatVideoNode, CustomOverflowError, CustomRuntimeError, FieldBased, FieldBasedT, FuncExceptT,
InvalidColorFamilyError, Keyframes, KwargsT, P, PlanesT, SceneChangeMode, Sentinel, check_ref_clip, check_variable,
clamp, clip_async_render, core, depth, disallow_variable_format, disallow_variable_resolution, fallback,
kwargs_fallback, normalize_planes, normalize_seq, scale_value, vs
kwargs_fallback, normalize_planes, normalize_seq, scale_8bit, vs
)

from ..prefilters import PelType, Prefilter, prefilter_to_full_range
Expand Down Expand Up @@ -789,7 +789,7 @@ def degrain(
'"limit" values should be between 0 and 255 (inclusive)!', self.degrain
)

limitf, limitCf = scale_value(limit, 8, ref, ColorRange.FULL), scale_value(limitC, 8, ref, ColorRange.FULL)
limitf, limitCf = scale_8bit(ref, limit), scale_8bit(ref, limitC)

thSCD1, thSCD2 = self.normalize_thscd(thSCD, thSAD, self.degrain)

Expand Down
4 changes: 2 additions & 2 deletions vsdenoise/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from vsrgtools.util import norm_rmode_planes
from vstools import (
CustomIndexError, CustomIntEnum, FuncExceptT, InvalidColorFamilyError, KwargsT, PlanesT, check_ref_clip,
check_variable, fallback, flatten_vnodes, get_y, normalize_planes, scale_8bit, scale_value, vs
ColorRange, check_variable, fallback, flatten_vnodes, get_y, normalize_planes, scale_8bit, scale_value, vs
)

from .fft import DFTTest, fft3d
Expand Down Expand Up @@ -94,7 +94,7 @@ def decrease_size(
if pm_min > pm_max:
raise CustomIndexError('The mask min must be lower than max!', decrease_size, dict(min=pm_min, max=pm_max))

pm_min, pm_max = scale_value(pm_min, 32, clip), scale_value(pm_max, 32, clip)
pm_min, pm_max = scale_value(pm_min, 32, clip, ColorRange.FULL), scale_value(pm_max, 32, clip, ColorRange.FULL)

yuv444 = Bilinear.resample(
range_mask(clip, rad=3, radc=2), clip.format.replace(subsampling_h=0, subsampling_w=0)
Expand Down
9 changes: 3 additions & 6 deletions vsdenoise/prefilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
from vstools import (
MISSING, ColorRange, ConvMode, CustomEnum, CustomIntEnum, CustomRuntimeError, MissingT, PlanesT, SingleOrArr,
SingleOrArrOpt, check_variable, clamp, core, depth, disallow_variable_format, disallow_variable_resolution,
get_depth, get_neutral_value, get_peak_value, get_y, join, normalize_planes, normalize_seq, scale_8bit, scale_value,
split, vs
get_neutral_value, get_peak_value, get_y, join, normalize_planes, normalize_seq, scale_8bit, split, vs
)

from .bm3d import BM3D as BM3DM
Expand Down Expand Up @@ -65,7 +64,6 @@ def _run(clip: vs.VideoNode, planes: PlanesT, **kwargs: Any) -> vs.VideoNode:

pref_type = Prefilter.MINBLUR3 if self == Prefilter.AUTO else self

bits = get_depth(clip)
peak = get_peak_value(clip)
planes = normalize_planes(clip, planes)

Expand Down Expand Up @@ -98,7 +96,7 @@ def _run(clip: vs.VideoNode, planes: PlanesT, **kwargs: Any) -> vs.VideoNode:
if pref_type == Prefilter.DFTTEST:
dftt = DFTTest(sloc={0.0: 4, 0.2: 9, 1.0: 15}, tr=0).denoise(clip, **kwargs)

i, j = (scale_value(x, 8, bits, range_out=ColorRange.FULL) for x in (16, 75))
i, j = (scale_8bit(clip, x) for x in (16, 75))

pref_mask = norm_expr(
get_y(clip),
Expand Down Expand Up @@ -855,7 +853,6 @@ def prefilter_to_full_range(pref: vs.VideoNode, range_conversion: float, planes:

assert (fmt := work_clip.format) and pref.format

bits = get_depth(pref)
is_integer = fmt.sample_type == vs.INTEGER

# Luma expansion TV->PC (up to 16% more values for motion estimation)
Expand Down Expand Up @@ -886,7 +883,7 @@ def prefilter_to_full_range(pref: vs.VideoNode, range_conversion: float, planes:
elif range_conversion > 0.0:
pref_full = retinex(work_clip, upper_thr=range_conversion, fast=False)
else:
pref_full = depth(work_clip, bits, range_out=ColorRange.FULL, range_in=ColorRange.LIMITED)
pref_full = depth(work_clip, pref, range_out=ColorRange.FULL, range_in=ColorRange.LIMITED)

if chroma:
return join(pref_full, *chroma, family=pref.format.color_family)
Expand Down
Loading