Skip to content
class

UnsharpMask

extendsPhotometricTransform[TripletParams]
UnsharpMask(blur_limit: tuple[int, int] = (3, 7), sigma_limit: float | tuple[float, float] = 0.0, alpha: tuple[float, float] = (0.2, 0.5), threshold: float = 10.0, p: float = 0.5)

Unsharp-mask sharpen via img + alpha*(img - blur) (Albumentations UnsharpMask).

Subtracts a Gaussian-blurred copy from the original and adds the high-frequency residual back, scaled by alpha. This is the photographic "unsharp mask" used to enhance edges without amplifying noise as much as a raw Laplacian sharpen would. The kernel size k and Gaussian sigma are sampled per call from blur_limit / sigma_limit; sigma defaults to the OpenCV-style heuristic 0.3 * ((k - 1) * 0.5 - 1.0) + 0.8 when the sampled value is non-positive.

Parameters

blur_limit(int, int)= (3, 7)
Inclusive range from which the Gaussian kernel size k is sampled (snapped to the next odd integer).
sigma_limitfloat or (float, float)= 0.0
Range from which the Gaussian standard deviation is sampled uniformly. A scalar s is treated as (0, s); 0 falls back to the kernel-derived heuristic above.
alpha(float, float)= (0.2, 0.5)
Range from which the residual blend weight is sampled uniformly; higher values yield a stronger sharpen.
thresholdfloat= 10.0
Reserved for parity with the reference framework's masked-residual variant; kept on the signature for forward compatibility but currently unused (every pixel is sharpened).
pfloat= 0.5
Probability of applying the transform.

Examples

>>> import lucid
>>> import lucid.utils.transforms as T
>>> tf = T.UnsharpMask(blur_limit=(3, 7), alpha=(0.2, 0.5), p=1.0)
>>> out = tf(T.Image(lucid.rand(3, 32, 32))).data
>>> tuple(out.shape)
(3, 32, 32)

Used by 1

Constructors

1
dunder

__init__

→None
__init__(blur_limit: tuple[int, int] = (3, 7), sigma_limit: float | tuple[float, float] = 0.0, alpha: tuple[float, float] = (0.2, 0.5), threshold: float = 10.0, p: float = 0.5)

Instance methods

1
fn

make_params

→TripletParams
make_params(img: Tensor)

Sample per-call random parameters for UnsharpMask.

Parameters

Image tensor; not inspected, carried through for dispatch.

Returns

TripletParams

Carries a (residual blend weight from alpha), b (Gaussian kernel side k stored as float so the triplet stays homogeneous), and c (Gaussian sigma).

Notes

k is forced odd via _odd. A non-positive sigma falls back to OpenCV's kernel-derived 0.3 * ((k - 1) * 0.5 - 1.0) + 0.8 heuristic.

Dunder methods

1