Sharpen
Sharpen the input image using either kernel-based or Gaussian interpolation method.
Implements two different approaches to image sharpening:
- Traditional kernel-based method using Laplacian operator
- Gaussian interpolation method (similar to Kornia's approach)
alphaRange for the visibility of sharpening effect. At 0, only the original image is visible, at 1.0 only its processed version is visible. Values should be in the range [0, 1]. Used in both methods. Default: (0.2, 0.5).
lightnessRange for the lightness of the sharpened image. Only used in 'kernel' method. Larger values create higher contrast. Values should be greater than 0. Default: (0.5, 1.0).
methodSharpening algorithm to use:
- 'kernel': Traditional kernel-based sharpening using Laplacian operator
- 'gaussian': Interpolation between Gaussian blurred and original image Default: 'kernel'
kernel_sizeSize of the Gaussian blur kernel for 'gaussian' method. Must be odd. Default: 5
sigmaStandard deviation for Gaussian kernel in 'gaussian' method. Default: 1.0
pProbability of applying the transform. Default: 0.5.
>>> import albumentations as A
>>> import numpy as np
# Traditional kernel sharpening
>>> transform = A.Sharpen(
... alpha=(0.2, 0.5),
... lightness=(0.5, 1.0),
... method='kernel',
... p=1.0
... )
# Gaussian interpolation sharpening
>>> transform = A.Sharpen(
... alpha=(0.5, 1.0),
... method='gaussian',
... kernel_size=5,
... sigma=1.0,
... p=1.0
... )- Kernel sizes must be odd to maintain spatial alignment
- Methods produce different visual results:
- Kernel method: More pronounced edges, possible artifacts
- Gaussian method: More natural look, limited to original sharpness
- Blur: For Gaussian blurring
- UnsharpMask: Alternative sharpening method
- RandomBrightnessContrast: For adjusting image contrast
- [{'description': 'R. C. Gonzalez and R. E. Woods, "Digital Image Processing (4th Edition),"', 'source': 'Chapter 3: Intensity Transformations and Spatial Filtering.'}, {'description': 'J. C. Russ, "The Image Processing Handbook (7th Edition),"', 'source': 'Chapter 4: Image Enhancement.'}, {'description': 'T. Acharya and A. K. Ray, "Image Processing', 'source': 'Principles and Applications,": Chapter 5: Image Enhancement.'}, {'description': 'Unsharp masking', 'source': 'https://en.wikipedia.org/wiki/Unsharp_masking'}, {'description': 'Laplacian operator', 'source': 'https://en.wikipedia.org/wiki/Laplace_operator'}, {'description': 'Gaussian blur', 'source': 'https://en.wikipedia.org/wiki/Gaussian_blur'}]