y5gfunc.filter.resample¶
resample
¶
Classes:
| Name | Description |
|---|---|
ColorMatrixManager |
Manager for a specific RGB-OPP conversion matrix and its related transformations. |
Functions:
| Name | Description |
|---|---|
register_opp_matrix |
Register a new OPP matrix variant and create its manager. |
yuv2opp |
Convert YUV to OPP color space. |
opp2yuv |
Convert OPP to YUV color space. |
rgb2opp |
Convert RGB to OPP color space. |
opp2rgb |
Convert OPP to RGB color space. |
nn2x |
Doubles the resolution of input clip with nnedi3. |
Gammarize |
|
SSIM_downsample |
SSIM downsampler |
Descale |
|
Attributes:
| Name | Type | Description |
|---|---|---|
STANDARD_OPP |
|
|
NORMALIZED_OPP |
|
|
MAWEN_OPP |
|
|
default_opp |
|
STANDARD_OPP
module-attribute
¶
STANDARD_OPP = register_opp_matrix('standard', Matrix([[Rational(1, 3), Rational(1, 3), Rational(1, 3)], [Rational(1, 2), Rational(-1, 2), 0], [Rational(1, 4), Rational(1, 4), Rational(-1, 2)]]))
NORMALIZED_OPP
module-attribute
¶
NORMALIZED_OPP = register_opp_matrix('normalized', Matrix([[Rational(1, 3), Rational(1, 3), Rational(1, 3)], [S(1) / sqrt(6), S(-1) / sqrt(6), 0], [S(1) / sqrt(18), S(1) / sqrt(18), S(-2) / sqrt(18)]]))
MAWEN_OPP
module-attribute
¶
MAWEN_OPP = register_opp_matrix('mawen', Matrix([[Rational(1, 3), Rational(1, 3), Rational(1, 3)], [Rational(1, 2), 0, Rational(-1, 2)], [Rational(1, 4), Rational(-1, 2), Rational(1, 4)]]))
ColorMatrixManager
¶
ColorMatrixManager(rgb_opp_matrix: Matrix, name: str)
Manager for a specific RGB-OPP conversion matrix and its related transformations.
Initialize the ColorMatrixManager with a specific RGB to OPP matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Matrix
|
A 3x3 sympy.Matrix for RGB to OPP conversion |
required |
|
str
|
Identifier for this specific OPP transform variant |
required |
Methods:
| Name | Description |
|---|---|
register_yuv_matrix |
Register a YUV to RGB matrix type. |
initialize |
Initialize all matrices and coefficients. |
get_yuv_to_opp_coefs |
Get YUV to OPP conversion coefficients for a specific matrix type. |
get_opp_to_yuv_coefs |
Get OPP to YUV conversion coefficients for a specific matrix type. |
get_rgb_to_opp_coefs |
Get RGB to OPP conversion coefficients. |
get_opp_to_rgb_coefs |
Get OPP to RGB conversion coefficients. |
Attributes:
| Name | Type | Description |
|---|---|---|
name |
|
Source code in y5gfunc/filter/resample.py
register_yuv_matrix
¶
register_yuv_matrix(matrix_ids: Union[Matrix, list[Matrix]], yuv_to_rgb_matrix: Matrix) -> None
Register a YUV to RGB matrix type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Union[Matrix, list[Matrix]]
|
The matrix id |
required |
|
Matrix
|
A sympy 3x3 Matrix representing YUV->RGB conversion |
required |
Source code in y5gfunc/filter/resample.py
initialize
¶
Initialize all matrices and coefficients.
Source code in y5gfunc/filter/resample.py
get_yuv_to_opp_coefs
¶
Get YUV to OPP conversion coefficients for a specific matrix type.
Source code in y5gfunc/filter/resample.py
get_opp_to_yuv_coefs
¶
Get OPP to YUV conversion coefficients for a specific matrix type.
Source code in y5gfunc/filter/resample.py
get_rgb_to_opp_coefs
¶
Get RGB to OPP conversion coefficients.
get_opp_to_rgb_coefs
¶
Get OPP to RGB conversion coefficients.
register_opp_matrix
¶
register_opp_matrix(name: str, rgb_opp_matrix: Matrix) -> ColorMatrixManager
Register a new OPP matrix variant and create its manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Name identifier for this OPP variant |
required |
|
Matrix
|
The 3x3 RGB to OPP conversion matrix |
required |
Returns:
| Type | Description |
|---|---|
ColorMatrixManager
|
The created ColorMatrixManager instance |
Source code in y5gfunc/filter/resample.py
yuv2opp
¶
yuv2opp(clip: VideoNode, matrix_in: Optional[Matrix] = None, range_in: Optional[ColorRange] = None, opp_manager: ColorMatrixManager = default_opp) -> VideoNode
Convert YUV to OPP color space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
VideoNode
|
Input YUV clip |
required |
|
Optional[Matrix]
|
Source matrix override, if None, read from clip properties |
None
|
|
Optional[ColorRange]
|
Source range override, if None, read from clip properties |
None
|
|
ColorMatrixManager
|
ColorMatrixManager for the specific OPP variant to use |
default_opp
|
Returns:
| Type | Description |
|---|---|
VideoNode
|
Clip in OPP color space with appropriate frame properties |
Source code in y5gfunc/filter/resample.py
opp2yuv
¶
opp2yuv(clip: VideoNode, target_matrix: Optional[Matrix] = None, target_range: Optional[ColorRange] = None, opp_manager: Optional[ColorMatrixManager] = None) -> VideoNode
Convert OPP to YUV color space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
VideoNode
|
Input OPP clip |
required |
|
Optional[Matrix]
|
Target YUV color space, if None, read from clip properties |
None
|
|
Optional[ColorRange]
|
Target range, if None, read from clip properties |
None
|
|
Optional[ColorMatrixManager]
|
ColorMatrixManager for the specific OPP variant, if None, read from clip properties |
None
|
Returns:
| Type | Description |
|---|---|
VideoNode
|
Clip in YUV color space |
Source code in y5gfunc/filter/resample.py
rgb2opp
¶
rgb2opp(clip: VideoNode, opp_manager: ColorMatrixManager = default_opp) -> VideoNode
Convert RGB to OPP color space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
VideoNode
|
Input RGB clip |
required |
|
ColorMatrixManager
|
ColorMatrixManager for the specific OPP variant to use |
default_opp
|
Returns:
| Type | Description |
|---|---|
VideoNode
|
Clip in OPP color space |
Source code in y5gfunc/filter/resample.py
opp2rgb
¶
opp2rgb(clip: VideoNode, opp_manager: Optional[ColorMatrixManager] = None) -> VideoNode
Convert OPP to RGB color space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
VideoNode
|
Input OPP clip |
required |
|
Optional[ColorMatrixManager]
|
ColorMatrixManager for the specific OPP variant, if None, read from clip properties |
None
|
Returns:
| Type | Description |
|---|---|
VideoNode
|
Clip in RGB color space |
Source code in y5gfunc/filter/resample.py
nn2x
¶
nn2x(clip: VideoNode, opencl: bool = True, nnedi3_args: dict[str, int] = {'field': 1, 'nsize': 4, 'nns': 4, 'qual': 2}) -> VideoNode
Doubles the resolution of input clip with nnedi3.
Source code in y5gfunc/filter/resample.py
Gammarize
¶
Source code in y5gfunc/filter/resample.py
SSIM_downsample
¶
SSIM_downsample(clip: VideoNode, width: int, height: int, smooth: Union[float, Callable] = 1, gamma: bool = True, fulls: bool = False, fulld: bool = False, curve: str = '709', sigmoid: bool = True, epsilon: float = 1e-06, **resample_args: Any) -> VideoNode
SSIM downsampler
SSIM downsampler is an image downscaling technique that aims to optimize for the perceptual quality of the downscaled results. Image downscaling is considered as an optimization problem where the difference between the input and output images is measured using famous Structural SIMilarity (SSIM) index. The solution is derived in closed-form, which leads to the simple, efficient implementation. The downscaled images retain perceptually important features and details, resulting in an accurate and spatio-temporally consistent representation of the high resolution input.
All the internal calculations are done at 32-bit float, except gamma correction is done at integer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
VideoNode
|
The input clip. |
required |
|
int
|
The width of the output clip. |
required |
|
int
|
The height of the output clip |
required |
|
Union[float, Callable]
|
The method to smooth the image. If it's an int, it specifies the "radius" of the internal used boxfilter, i.e. the window has a size of (2smooth+1)x(2smooth+1). If it's a float, it specifies the "sigma" of core.tcanny.TCanny, i.e. the standard deviation of gaussian blur. If it's a function, it acs as a general smoother. |
1
|
|
bool
|
Set to true to turn on gamma correction for the y channel. |
True
|
|
bool
|
Specifies if the luma is limited range (False) or full range (True) |
False
|
|
bool
|
Same as fulls, but for output. |
False
|
|
str
|
Type of gamma mapping. |
'709'
|
|
bool
|
When True, applies a sigmoidal curve after the power-like curve (or before when converting from linear to gamma-corrected). This helps reducing the dark halo artifacts around sharp edges caused by resizing in linear luminance. |
True
|
|
Any
|
Additional arguments passed to |
{}
|
Returns:
| Type | Description |
|---|---|
VideoNode
|
Downsampled clip in 32-bit format. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Ref
[1] Oeztireli, A. C., & Gross, M. (2015). Perceptually based downscaling of images. ACM Transactions on Graphics (TOG), 34(4), 77.
Source code in y5gfunc/filter/resample.py
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 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
Descale
¶
Descale(src: VideoNode, width: int, height: int, kernel: str, custom_kernel: Optional[Callable] = None, taps: int = 3, b: Union[int, float] = 0.0, c: Union[int, float] = 0.5, blur: Union[int, float] = 1.0, post_conv: Optional[list[Union[float, int]]] = None, src_left: Union[int, float] = 0.0, src_top: Union[int, float] = 0.0, src_width: Optional[Union[int, float]] = None, src_height: Optional[Union[int, float]] = None, border_handling: int = 0, ignore_mask: Optional[VideoNode] = None, force: bool = False, force_h: bool = False, force_v: bool = False, opt: int = 0) -> VideoNode
Source code in y5gfunc/filter/resample.py
529 530 531 532 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 | |