funcs ¶
This module contains general denoising functions built on top of base denoisers.
Functions:
-
ccd–Camcorder Color Denoise (CCD) - chroma denoiser adapted from the original VirtualDub filter by Sergey Stolyarevsky.
-
mc_clamp–Motion-compensated clamping of a filtered clip against the source.
-
mc_degrain–Perform temporal denoising using motion compensation.
ccd ¶
ccd(
clip: VideoNode,
thr: float = 4,
tr: int = 0,
ref_points: Sequence[bool] = (True, True, False),
scale: float | None = None,
pscale: float = 0.0,
chroma_upscaler: ScalerLike = _LanczosChroma(
format=lambda clip: replace(
color_family=RGB, subsampling_w=0, subsampling_h=0
)
),
chroma_downscaler: KernelLike = Catrom,
planes: Planes | MissingT = MISSING,
func: FuncExcept | None = None,
) -> VideoNode
Camcorder Color Denoise (CCD) - chroma denoiser adapted from the original VirtualDub filter by Sergey Stolyarevsky.
It works best on analog or low-quality digital sources such as VHS or DVD captures.
Example usage
denoised = ccd(clip, thr=6, tr=1, chroma_upscaler=Lanczos(format=vs.RGB48))
Parameters:
-
(clip¶VideoNode) –Source clip.
-
(thr¶float, default:4) –Euclidean distance threshold for including pixel in the matrix. Higher values results in stronger denoising. Automatically scaled to all bit depths internally.
-
(tr¶int, default:0) –Temporal radius of processing. Higher values result in more denoising.
-
(ref_points¶Sequence[bool], default:(True, True, False)) –Specifies whether to use the low, medium, or high reference points (or any combination), respectively, in the processing matrix. The default uses the low and medium, but excludes the high points. See zsmooth.CCD for details.
-
(scale¶float | None, default:None) –Matrix size multiplier.
1= 25x25 matrix (original CCD)2= 50x50, and so on.
-
(pscale¶float, default:0.0) –Correction strength for chroma ringing introduced during downscaling.
-
(chroma_upscaler¶ScalerLike, default:_LanczosChroma(format=lambda clip: replace(color_family=RGB, subsampling_w=0, subsampling_h=0))) –Upscaler for converting YUV input to full-resolution RGB before processing.
-
(chroma_downscaler¶KernelLike, default:Catrom) –Kernel used to downscale the denoised RGB result back to the input format.
-
(planes¶Planes | MissingT, default:MISSING) –Planes to process. Defaults to chroma for YUV input, all planes otherwise.
-
(func¶FuncExcept | None, default:None) –Function returned for custom error handling. This should only be set by VS package developers.
Raises:
-
CustomRuntimeError–If
chroma_upscalerfails to produce full-resolution chroma.
Returns:
-
VideoNode–Denoised clip.
Source code in vsdenoise/funcs.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
mc_clamp ¶
mc_clamp(
flt: VideoNode,
src: VideoNode,
mv_obj: MVTools,
clamp: int | float | tuple[int | float, int | float] = 0,
func: FuncExcept | None = None,
**kwargs: Any
) -> VideoNode
Motion-compensated clamping of a filtered clip against the source.
This function clamps the values of a filtered clip flt to those of the source clip src. but instead of using a spatial neighborhood (e.g. 3x3), it computes temporal min/max ranges from motion-compensated neighboring frames.
This helps to preserve temporal consistency and prevent over/undershoot artifacts in motion areas.
Parameters:
-
(flt¶VideoNode) –The filtered clip to be clamped.
-
(src¶VideoNode) –The original source clip, used as a reference for clamping.
-
(mv_obj¶MVTools) –An MVTools object providing motion vectors for compensation.
-
(clamp¶int | float | tuple[int | float, int | float], default:0) –Clamping thresholds. Can be:
- single value (applied symmetrically to undershoot and overshoot),
- tuple (undershoot, overshoot) for asymmetric clamping.
Values are scaled according to clip bit depth. Defaults to 0 (no additional clamping margin).
-
(func¶FuncExcept | None, default:None) –Function returned for custom error handling. This should only be set by VS package developers.
-
(**kwargs¶Any, default:{}) –Additional keyword arguments passed to mv_obj.compensate.
Returns:
-
VideoNode–The motion-compensated clamped clip.
Source code in vsdenoise/funcs.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
mc_degrain ¶
mc_degrain(
clip: VideoNode,
vectors: MotionVectors | None = None,
prefilter: VideoNode | PrefilterLike | VSFunctionNoArgs | None = None,
mfilter: VideoNode | VSFunctionNoArgs | None = None,
preset: MVToolsPreset = ...,
tr: int = 1,
blksize: int | tuple[int, int] = 16,
overlap: int | tuple[int, int] = 2,
refine: int = 1,
thsad: int | tuple[int, int] = 400,
thsad2: int | tuple[int | None, int | None] | None = None,
thsad_recalc: int | None = None,
limit: int | tuple[int | None, int | None] | None = None,
thscd: int | tuple[int | None, int | None] | None = None,
export_globals: Literal[False] = False,
planes: Planes = None,
) -> VideoNode
mc_degrain(
clip: VideoNode,
vectors: MotionVectors | None = None,
prefilter: VideoNode | PrefilterLike | VSFunctionNoArgs | None = None,
mfilter: VideoNode | VSFunctionNoArgs | None = None,
preset: MVToolsPreset = ...,
tr: int = 1,
blksize: int | tuple[int, int] = 16,
overlap: int | tuple[int, int] = 2,
refine: int = 1,
thsad: int | tuple[int, int] = 400,
thsad2: int | tuple[int | None, int | None] | None = None,
thsad_recalc: int | None = None,
limit: int | tuple[int | None, int | None] | None = None,
thscd: int | tuple[int | None, int | None] | None = None,
*,
export_globals: Literal[True],
planes: Planes = None
) -> tuple[VideoNode, MVTools]
mc_degrain(
clip: VideoNode,
vectors: MotionVectors | None = None,
prefilter: VideoNode | PrefilterLike | VSFunctionNoArgs | None = None,
mfilter: VideoNode | VSFunctionNoArgs | None = None,
preset: MVToolsPreset = ...,
tr: int = 1,
blksize: int | tuple[int, int] = 16,
overlap: int | tuple[int, int] = 2,
refine: int = 1,
thsad: int | tuple[int, int] = 400,
thsad2: int | tuple[int | None, int | None] | None = None,
thsad_recalc: int | None = None,
limit: int | tuple[int | None, int | None] | None = None,
thscd: int | tuple[int | None, int | None] | None = None,
export_globals: bool = ...,
planes: Planes = None,
) -> VideoNode | tuple[VideoNode, MVTools]
mc_degrain(
clip: VideoNode,
vectors: MotionVectors | None = None,
prefilter: VideoNode | PrefilterLike | VSFunctionNoArgs | None = None,
mfilter: VideoNode | VSFunctionNoArgs | None = None,
preset: MVToolsPreset = HQ_SAD,
tr: int = 1,
blksize: int | tuple[int, int] = 16,
overlap: int | tuple[int, int] = 2,
refine: int = 1,
thsad: int | tuple[int, int] = 400,
thsad2: int | tuple[int | None, int | None] | None = None,
thsad_recalc: int | None = None,
limit: int | tuple[int | None, int | None] | None = None,
thscd: int | tuple[int | None, int | None] | None = None,
export_globals: bool = False,
planes: Planes = None,
) -> VideoNode | tuple[VideoNode, MVTools]
Perform temporal denoising using motion compensation.
Motion compensated blocks from previous and next frames are averaged with the current frame. The weighting factors for each block depend on their SAD from the current frame.
Parameters:
-
(clip¶VideoNode) –The clip to process.
-
(vectors¶MotionVectors | None, default:None) –Motion vectors to use.
-
(prefilter¶VideoNode | PrefilterLike | VSFunctionNoArgs | None, default:None) –Filter or clip to use when performing motion vector search.
-
(mfilter¶VideoNode | VSFunctionNoArgs | None, default:None) –Filter or clip to use where degrain couldn't find a matching block.
-
(preset¶MVToolsPreset, default:HQ_SAD) –MVTools preset defining base values for the MVTools object. Default is HQ_SAD.
-
(tr¶int, default:1) –The temporal radius. This determines how many frames are analyzed before/after the current frame.
-
(blksize¶int | tuple[int, int], default:16) –Size of a block. Larger blocks are less sensitive to noise, are faster, but also less accurate.
-
(overlap¶int | tuple[int, int], default:2) –The blksize divisor for block overlap. Larger overlapping reduces blocking artifacts.
-
(refine¶int, default:1) –Number of times to recalculate motion vectors with halved block size.
-
(thsad¶int | tuple[int, int], default:400) –Defines the soft threshold of block sum absolute differences. Blocks with SAD above this threshold have zero weight for averaging (denoising). Blocks with low SAD have highest weight. The remaining weight is taken from pixels of source clip.
-
(thsad2¶int | tuple[int | None, int | None] | None, default:None) –Define the SAD soft threshold for frames with the largest temporal distance. The actual SAD threshold for each reference frame is interpolated between thsad (nearest frames) and thsad2 (furthest frames). Only used with the FLOAT MVTools plugin.
-
(thsad_recalc¶int | None, default:None) –Only bad quality new vectors with a SAD above this will be re-estimated by search. thsad value is scaled to 8x8 block size.
-
(limit¶int | tuple[int | None, int | None] | None, default:None) –Maximum allowed change in pixel values.
-
(thscd¶int | tuple[int | None, int | None] | None, default:None) –Scene change detection thresholds:
- First value: SAD threshold for considering a block changed between frames.
- Second value: Percentage of changed blocks needed to trigger a scene change.
-
(export_globals¶bool, default:False) –Whether to return the MVTools object.
-
(planes¶Planes, default:None) –Which planes to process. Default: None (all planes).
Returns:
-
VideoNode | tuple[VideoNode, MVTools]–Motion compensated and temporally filtered clip with reduced noise. If export_globals is true: A tuple
-
VideoNode | tuple[VideoNode, MVTools]–containing the processed clip and the MVTools object.
Source code in vsdenoise/funcs.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |