blockmatch ¶
Functions:
-
bm3d–Block-Matching and 3D filtering (BM3D) is a state-of-the-art algorithm for image denoising.
-
wnnm–WNNM is a denoising algorithm based on block-matching and weighted nuclear norm minimization.
BM3D ¶
BM3D(bm3d_func: Callable[P, R])
Class decorator that wraps the bm3d function and extends its functionality.
It is not meant to be used directly.
Classes:
-
Backend–Enum representing the available backends for running the BM3D plugin.
-
Profile–Enum representing the available BM3D profiles, each with default parameter settings.
Methods:
-
__call__–
Attributes:
-
matrix_opp2rgb(tuple[float, ...]) –Matrix to convert OPP (Opponent) color space back to RGB color space.
-
matrix_rgb2opp(tuple[float, ...]) –Matrix to convert RGB color space to OPP (Opponent) color space.
Source code in vsdenoise/blockmatch.py
165 166 167 168 | |
matrix_opp2rgb class-attribute instance-attribute ¶
Matrix to convert OPP (Opponent) color space back to RGB color space.
matrix_rgb2opp class-attribute instance-attribute ¶
matrix_rgb2opp: tuple[float, ...] = (
1 / 3,
1 / 3,
1 / 3,
1 / 2,
0,
-1 / 2,
1 / 4,
-1 / 2,
1 / 4,
)
Matrix to convert RGB color space to OPP (Opponent) color space.
Backend ¶
Bases: CustomEnum
Enum representing the available backends for running the BM3D plugin.
Methods:
-
from_param–Return the enum value from a parameter.
-
resolve–Resolves the appropriate BM3D backend to use.
Attributes:
-
AUTO–Automatically selects the best available backend.
-
CPU–Optimized CPU implementation using AVX and AVX2 intrinsics.
-
CUDA–GPU implementation using NVIDIA CUDA.
-
CUDA_RTC–GPU implementation using NVIDIA CUDA with NVRTC (runtime compilation).
-
HIP–GPU implementation using AMD HIP.
-
METAL–GPU implementation using Apple Metal.
-
OLD–Reference VapourSynth-BM3D implementation.
-
SYCL–GPU implementation using Intel SYCL.
-
plugin(Plugin) –Returns the appropriate BM3D plugin based on the current backend.
AUTO class-attribute instance-attribute ¶
AUTO = 'auto'
Automatically selects the best available backend.
Selection priority: "CUDA_RTC" → "CUDA" → "HIP" → "SYCL" → "METAL" → "CPU" → "OLD".
CPU class-attribute instance-attribute ¶
CPU = 'bm3dcpu'
Optimized CPU implementation using AVX and AVX2 intrinsics.
CUDA_RTC class-attribute instance-attribute ¶
CUDA_RTC = 'bm3dcuda_rtc'
GPU implementation using NVIDIA CUDA with NVRTC (runtime compilation).
METAL class-attribute instance-attribute ¶
METAL = 'bm3dmetal'
GPU implementation using Apple Metal.
plugin property ¶
plugin: Plugin
Returns the appropriate BM3D plugin based on the current backend.
Returns:
-
Plugin–The corresponding BM3D plugin for the resolved backend.
from_param classmethod ¶
from_param(value: Any, func_except: FuncExcept | None = None) -> Self
Return the enum value from a parameter.
Parameters:
-
(value¶Any) –Value to instantiate the enum class.
-
(func_except¶FuncExcept | None, default:None) –Exception function.
Returns:
-
Self–Enum value.
Raises:
-
NotFoundEnumValue–Variable not found in the given enum.
Source code in jetpytools/enums/base.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
resolve cached ¶
resolve() -> Backend
Resolves the appropriate BM3D backend to use.
If the current instance is not AUTO, it returns itself. Otherwise, it attempts to select the best available backend.
Raises:
-
CustomRuntimeError–If no supported BM3D implementation is available on the system.
Returns:
-
Backend–The resolved BM3D.Backend to use for processing.
Source code in vsdenoise/blockmatch.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
Profile ¶
Bases: CustomStrEnum
Enum representing the available BM3D profiles, each with default parameter settings.
For more detailed information on these profiles, refer to the original documentation.
Methods:
-
basic_args–Retrieves the arguments for the basic estimate step based on the specified radius.
-
config–Retrieves the configuration for each BM3D profile.
-
final_args–Retrieves the arguments for the final estimate step based on the specified radius.
-
from_param–Return the enum value from a parameter.
-
value–
Attributes:
-
FAST–A profile optimized for maximum processing speed.
-
HIGH–A profile focused on achieving high-precision denoising.
-
LOW_COMPLEXITY–A profile designed for content with low-complexity noise.
-
NORMAL–A neutral profile.
-
VERY_NOISY–A profile tailored for handling very noisy content.
FAST class-attribute instance-attribute ¶
FAST = 'fast'
A profile optimized for maximum processing speed.
HIGH class-attribute instance-attribute ¶
HIGH = 'high'
A profile focused on achieving high-precision denoising.
LOW_COMPLEXITY class-attribute instance-attribute ¶
LOW_COMPLEXITY = 'lc'
A profile designed for content with low-complexity noise.
VERY_NOISY class-attribute instance-attribute ¶
VERY_NOISY = 'vn'
A profile tailored for handling very noisy content.
basic_args ¶
Retrieves the arguments for the basic estimate step based on the specified radius.
Parameters:
Returns:
Source code in vsdenoise/blockmatch.py
488 489 490 491 492 493 494 495 496 497 498 | |
config ¶
config() -> MappingProxyType[
str, MappingProxyType[str, MappingProxyType[str, Any]]
]
Retrieves the configuration for each BM3D profile.
Source code in vsdenoise/blockmatch.py
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 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | |
final_args ¶
Retrieves the arguments for the final estimate step based on the specified radius.
Parameters:
Returns:
Source code in vsdenoise/blockmatch.py
500 501 502 503 504 505 506 507 508 509 510 | |
from_param classmethod ¶
from_param(value: Any, func_except: FuncExcept | None = None) -> Self
Return the enum value from a parameter.
Parameters:
-
(value¶Any) –Value to instantiate the enum class.
-
(func_except¶FuncExcept | None, default:None) –Exception function.
Returns:
-
Self–Enum value.
Raises:
-
NotFoundEnumValue–Variable not found in the given enum.
Source code in jetpytools/enums/base.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
__call__ ¶
__call__(*args: P.args, **kwargs: P.kwargs) -> R
Source code in vsdenoise/blockmatch.py
170 171 | |
UnsupportedProfileError ¶
UnsupportedProfileError(
message: SupportsString | None = None,
func: FuncExcept | None = None,
reason: Any = None,
**kwargs: Any,
)
Bases: CustomValueError
Raised when an unsupported profile is passed.
Instantiate a new exception with pretty printing and more.
Parameters:
-
(message¶SupportsString | None, default:None) –Message of the error.
-
(func¶FuncExcept | None, default:None) –Function this exception was raised from.
-
(reason¶Any, default:None) –Reason of the exception. For example, an optional parameter.
Methods:
-
__call__–Copy an existing exception with defaults and instantiate a new one.
-
catch–Create a context manager that catches exceptions of this class type.
Attributes:
Source code in jetpytools/exceptions/base.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
__call__ ¶
__call__(
message: SupportsString | None | MissingT = MISSING,
func: FuncExcept | None | MissingT = MISSING,
reason: SupportsString | FuncExcept | None | MissingT = MISSING,
**kwargs: Any,
) -> Self
Copy an existing exception with defaults and instantiate a new one.
Parameters:
-
(message¶SupportsString | None | MissingT, default:MISSING) –Message of the error.
-
(func¶FuncExcept | None | MissingT, default:MISSING) –Function this exception was raised from.
-
(reason¶SupportsString | FuncExcept | None | MissingT, default:MISSING) –Reason of the exception. For example, an optional parameter.
Source code in jetpytools/exceptions/base.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
catch classmethod ¶
catch() -> CatchError[Self]
Create a context manager that catches exceptions of this class type.
Returns:
-
CatchError[Self]–CatchError[Self]: A context manager that will catch and store exceptions of type
clswhen used in awithblock.
Source code in jetpytools/exceptions/base.py
140 141 142 143 144 145 146 147 148 149 | |
bm3d ¶
bm3d(
clip: VideoNode,
sigma: float | Sequence[float] = 0.5,
tr: int | Sequence[int | None] | None = None,
refine: int = 1,
profile: Profile = FAST,
pre: VideoNode | None = None,
ref: VideoNode | None = None,
backend: Backend = AUTO,
basic_args: dict[str, Any] | None = None,
final_args: dict[str, Any] | None = None,
planes: Planes = None,
**kwargs: Any,
) -> VideoNode
Block-Matching and 3D filtering (BM3D) is a state-of-the-art algorithm for image denoising.
More information at
- https://github.com/HomeOfVapourSynthEvolution/VapourSynth-BM3D/
- https://github.com/WolframRhodium/VapourSynth-BM3DCUDA
Example
denoised = bm3d(clip, 1.25, 1, profile=bm3d.Profile.NORMAL, backend=bm3d.Backend.CUDA_RTC, ...)
Parameters:
-
(clip¶VideoNode) –The clip to process. If using BM3D.Backend.OLD, the clip format must be YUV444 or RGB, as filtering is always performed in the OPPonent color space. If using another device type and the clip format is:
- RGB -> Processed in OPP format (BM3D algorithm, aka
chroma=False). - YUV444 -> Processed in YUV444 format (CBM3D algorithm, aka
chroma=True). - GRAY -> Processed as-is.
- YUVXXX -> Each plane is processed separately.
- RGB -> Processed in OPP format (BM3D algorithm, aka
-
(sigma¶float | Sequence[float], default:0.5) –Strength of denoising. Valid range is [0, +inf). A sequence of up to 3 elements can be used to set different sigma values for the Y, U, and V channels. If fewer than 3 elements are given, the last value is repeated. Defaults to 0.5.
-
(tr¶int | Sequence[int | None] | None, default:None) –The temporal radius for denoising. Valid range is [1, 16]. Defaults to the radius defined by the profile.
-
(refine¶int, default:1) –Number of refinement steps.
- 0 means basic estimate only.
- 1 means basic estimate with one final estimate.
- n means basic estimate refined with a final estimate n times.
-
(profile¶Profile, default:FAST) –The preset profile. Defaults to BM3D.Profile.FAST.
-
(pre¶VideoNode | None, default:None) –A pre-filtered clip for the basic estimate. It should be more suitable for block-matching than the input clip, and must be of the same format and dimensions. Either
preorrefcan be specified, not both. Defaults to None. -
(ref¶VideoNode | None, default:None) –A clip to be used as the basic estimate. It replaces BM3D's internal basic estimate and serves as the reference for the final estimate. Must be of the same format and dimensions as the input clip. Either
reforprecan be specified, not both. Defaults to None. -
(backend¶Backend, default:AUTO) –The backend to use for processing. Defaults to BM3D.Backend.AUTO.
-
(basic_args¶dict[str, Any] | None, default:None) –Additional arguments to pass to the basic estimate step. Defaults to None.
-
(final_args¶dict[str, Any] | None, default:None) –Additional arguments to pass to the final estimate step. Defaults to None.
-
(planes¶Planes, default:None) –Planes to process. Default to all.
-
(**kwargs¶Any, default:{}) –Internal keyword arguments for testing purposes.
Raises:
-
CustomValueError–If both
preandrefare specified at the same time. -
UnsupportedProfileError–If the VERY_NOISY profile is not supported by the selected device type.
-
UnsupportedVideoFormatError–If the video format is not supported when using BM3D.Backend.OLD.
Returns:
-
VideoNode–Denoised clip.
Source code in vsdenoise/blockmatch.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 | |
wnnm ¶
wnnm(
clip: VideoNode,
sigma: float | Sequence[float] = 3.0,
tr: int | None = None,
ref: VideoNode | None = None,
block_size: int | None = None,
block_step: int | None = None,
group_size: int | None = None,
bm_range: int | None = None,
ps_num: int | None = None,
ps_range: int | None = None,
residual: bool | None = None,
adaptive_aggregation: bool | None = None,
refine: int = 0,
merge_factor: float = 0.1,
planes: Planes = None,
) -> VideoNode
WNNM is a denoising algorithm based on block-matching and weighted nuclear norm minimization.
Block matching, which is popularized by BM3D, finds similar blocks and then stacks together in a 3-D group. The similarity between these blocks allows details to be preserved during denoising.
In contrast to BM3D, which denoises the 3-D group based on frequency domain filtering, WNNM utilizes weighted nuclear norm minimization, a kind of low rank matrix approximation. Because of this, WNNM exhibits less blocking and ringing artifact compared to BM3D, but the computational complexity is much higher. This stage is called collaborative filtering in BM3D.
For more information, see the WNNM README.
Parameters:
-
(clip¶VideoNode) –The input clip. Must be of 32 bit float format. Each plane is denoised separately.
-
(sigma¶float | Sequence[float], default:3.0) –Denoising strength of each plane. Larger values remove more noise but may smooth fine details. Accepts either a single float (applied to all planes) or a per-plane sequence. The valid range is [0, +inf), though practical values usually fall between 0.35 and 1.0. Values above 4.0 are rarely useful.
-
(tr¶int | None, default:None) –The temporal radius for denoising, valid range [1, 16]. For each processed frame, (radius * 2 + 1) frames will be requested, Increasing radius only increases tiny computational cost in block-matching and aggregation, and will not affect collaborative filtering, but the memory consumption can grow quadratically. Thus, feel free to use large radius as long as your RAM is large enough.
-
(ref¶VideoNode | None, default:None) –Reference clip for block matching. Must be of the same dimensions and format as
clip. -
(block_size¶int | None, default:None) –The size of a block is block_size x block_size (the 1st and the 2nd dimension), valid range [1,64]. A block is the basic processing unit of WNNM, representing a local patch. Generally, larger block will be slower, especially in the DCT/IDCT part. While at the same time, larger block_size allows you to set larger block_step, resulting in less block to be processed. 8 is a well-balanced value, both for quality and speed.
-
(block_step¶int | None, default:None) –Sliding step to process every next reference block, valid range [1,block_size]. Total number of reference blocks to be processed can be calculated approximately by (width / block_step) * (height / block_step). Smaller step results in processing more reference blocks, and is slower.
-
(group_size¶int | None, default:None) –Maximum number of similar blocks in each group (the 3rd dimension), valid range [1,256]. Larger value allows more blocks in a single group. Thus, the sparsity in a transformed group raises, the filtering will be stronger, and also slower in the DCT/IDCT part. When set to 1, no block-matching will be performed and each group only consists of the reference block.
-
(bm_range¶int | None, default:None) –Length of the side of the search neighborhood for block-matching, valid range [1, +inf). The size of search window is (bm_range * 2 + 1) x (bm_range * 2 + 1). Larger is slower, with more chances to find similar patches.
-
(ps_num¶int | None, default:None) –The number of matched locations used for predictive search, valid range [1, group_size]. Larger value increases the possibility to match more similar blocks, with tiny increasing in computational cost.
-
(ps_range¶int | None, default:None) –Length of the side of the search neighborhood for predictive-search block-matching, valid range [1, +inf)
-
(residual¶bool | None, default:None) –Whether to center blocks before collaborative filtering. Default: False.
-
(adaptive_aggregation¶bool | None, default:None) –Whether to aggregate blocks adaptively. Default: True.
-
(refine¶int, default:0) –Number of additional refinement iterations to perform.
A value of 0 corresponds to a single WNNM pass (equivalent to
num_iterations=1in the original implementation). Each increment adds another iterative regularization step using the previously denoised result.Valid range is [0, +inf).
-
(merge_factor¶float, default:0.1) –Blend factor for merging the last and current iteration during iterative regularization.
-
(planes¶Planes, default:None) –Which planes to process. Default to all.
Returns:
-
VideoNode–Denoised clip.
Source code in vsdenoise/blockmatch.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 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 | |