参考网址:http://www.harrisgeospatial.com/docs/unsharp_mask.html
The UNSHARP_MASK function performs an unsharp-mask sharpening filter on a two-dimensional array or a TrueColor image. For TrueColor images the unsharp mask is applied to each channel.
The unsharp mask algorithm works by enhancing the contrast between neighboring pixels in an image, and is widely used for astronomical images and for digital photographs.
The algorithm involves the following steps:
- Smooth the original image with a Gaussian filter, with the width controlled by the RADIUS keyword.
- Subtract the smoothed image from the original to create a high-pass filtered image.
- Apply any clipping needed on the high-pass image, as controlled by the THRESHOLD keyword.
- Add a certain percentage of the high-pass filtered image to the original image, with the percentage controlled by the AMOUNT keyword.
In pseudocode this algorithm can be written as:
HighPass = Image - Convol ( Image, Gaussian )Result = Image + A * HighPass * ( |HighPass| ≥ T )
where A is the amount, T is the threshold, and ≥ indicates a Boolean operation, 1 if true, or 0 otherwise.
Note: To avoid overflow for byte or integer data, the computations are performed using a larger integer type, the result is clipped to the minimum and maximum values for the original type, and the result is then converted back to the original type.
This routine is written in the IDL language. Its source code can be found in the file unsharp_mask.pro in the lib subdirectory of the IDL distribution.
使用python库PIL中的函数实现如下:
alpha_pil = Image.open('alpha.png') # 这里读入的直接是一个掩码图
alpha_pil = alpha_pil.filter(ImageFilter.UnsharpMask)