Skip to content

Commit

Permalink
Modify Gaussian's curve to take the standard sigma over fmtc's scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Setsugennoao committed Nov 5, 2023
1 parent 57ad981 commit 7c64c45
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions vskernels/kernels/various.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from __future__ import annotations

from math import log, sqrt
from typing import Any

from vstools import CustomValueError, to_singleton

from .fmtconv import FmtConv
from .placebo import Placebo

Expand Down Expand Up @@ -51,8 +54,50 @@ class Gaussian(FmtConv):

_kernel = 'gaussian'

def __init__(self, curve: float = 30, taps: int = 2, **kwargs: Any) -> None:
super().__init__(taps, a1=curve, **kwargs)
def __init__(self, sigma: float = 0.5, taps: int = 2, **kwargs: Any) -> None:
"""
Sigma is imagemagick's sigma scaling.
This will internally be scaled to fmtc's curve.
You can specify "curve" to override sigma and specify the original `a1` value.
"""
if 'curve' in kwargs:
a1 = kwargs.pop('curve')

if a1 is not None:
if a1 < 1.0 or a1 > 100.0:
raise CustomValueError("curve must be in range 1-100! (inclusive)")
else:
a1 = self.sigma.to_fmtc(sigma)

low, up = self.sigma.from_fmtc(100), self.sigma.from_fmtc(1)

if a1 < 1.0 or a1 > 100.0:
raise CustomValueError(f"sigma must be in range {low:.4f}-{up:.4f}! (inclusive)")

super().__init__(taps, a1=a1, **kwargs)

@to_singleton
class sigma:
def from_fmtc(self, curve: float) -> float:
if not curve:
return 0.0
return sqrt(1.0 / (2.0 * (curve / 10.0) * log(2)))

def to_fmtc(self, sigma: float) -> float:
if not sigma:
return 0.0
return 10 / (2 * log(2) * (sigma ** 2))

def from_libplacebo(self, sigma: float) -> float:
if not sigma:
return 0.0
return sqrt(sigma / 4)

def to_libplacebo(self, sigma: float) -> float:
if not sigma:
return 0.0
return 4 * (sigma ** 2)


class EwaBicubic(Placebo):
Expand Down

0 comments on commit 7c64c45

Please sign in to comment.