# 拉普拉斯锐化（Laplacian sharpening）(Laplacian sharpening)-其他

## 拉普拉斯锐化（Laplacian sharpening）(Laplacian sharpening)

在图像增强中，平滑是为了消除图像中噪声的干扰，或者降低对比度，与之相反，有时为了强调图像的边缘和细节，需要对图像进行锐化，提高对比度。图的边缘是指在局部不连续的特征。原理 　　拉普拉斯锐化图像是根据图像某个像素的周围像素到此像素的突变程度有关，也就是说它的依据是图像像素的变化程度。我们知道，一个函数的一阶微分描述了函数图像是朝哪里变化的，即增长或者降低；而二阶微分描述的则是图像变化的速度，急剧增长下降还是平缓的增长下降。那么据此我们可以猜测出依据二阶微分能够找到图像的色素的过渡程度，例如白色到黑色的过渡就是比较急剧的。 　　或者用官方点的话说：当邻域中心像素灰度低于它所在的领域内其它像素的平均灰度时，此中心像素的灰度应被进一步降低，当邻域中心像素灰度高于它所在的邻域内其它像素的平均灰度时，此中心像素的灰度应被进一步提高，以此实现图像的锐化处理。应用 　　运用拉普拉斯可以增强图像的细节，找到图像的边缘。但是有时候会把噪音也给增强了，那么可以在锐化前对图像进行平滑处理。　　下面我们来推导二阶微分与像素的关系： 　　先看一阶偏微分和推出的二元函数微分：

$\begin{array}{l}&\frac{\partial f}{\partial x}=f(x, y)-f(x-1, y) \\&\frac{\partial f}{\partial y}=f(x, y)-f(x, y-1) \\&\nabla \mathrm{f}=\frac{\partial f}{\partial x}+\frac{\partial f}{\partial y}=2 f(x, y)-f(x-1, y)-f(x, y-1)\end{array}$

一阶微分法能够用来检测边缘是否存在。

那么二阶微分法，也就是拉普拉斯算子就可以确定边缘的位置。（有的文章中称下式为拉普拉斯掩膜中心系数

$\nabla^{2} \mathrm{f}=4 f(x, y)-f(x-1, y)-f(x, y+1)-f(x+1, y)-f(x, y-1)$

这样可以找到一个模板矩阵：

$\begin{array}{ccc}0 & -1 & 0 \\-1 & 4 & -1 \\0 & -1 & 0\end{array}$

这个成为四邻域也就是上面的二阶微分法

$\begin{array}{ccc}-1 & -1 & -1 \\-1 & 8 & -1 \\-1 & -1 & -1\end{array}$

这个是八邻域。

【注】从上面的两种模板中就可以看出，如果一个黑色平面中有一个白点，那么模板矩阵可以使这个白点更亮。由于图像边缘就是灰度发生跳变的区域，所以拉普拉斯模板对边缘检测很有用。

八邻域的表示法为：

$\begin{array}{r}\nabla^{2} \mathrm{f}=8 f(x, y)-f(x-1, y-1)-f(x-1, y)-f(x-1, y+1)-f(x, y-1) \\-f(x, y+1)-f(x+1, y-1)+f(x+1, y)-f(x+1, y+1)\end{array}$

将算得的值替换原  $(x,y)$  处的像素值，可以得到类似边界的地方，然后根据下式得到锐化图像：

$\mathrm{g}(\mathrm{x})=\left\{\begin{array}{ll}\mathrm{f}(\mathrm{x}, \mathrm{y})-\nabla^{2} f(x, y), & \nabla^{2} f(x, y)<0 \\\mathrm{f}(\mathrm{x}, \mathrm{y})+\nabla^{2} f(x, y), & \nabla^{2} f(x, y) \geq 0\end{array}\right.$

————————

In image enhancement, smoothing is to eliminate the interference of noise in the image or reduce the contrast. On the contrary, sometimes in order to emphasize the edges and details of the image, it is necessary to sharpen the image and improve the contrast. The edge of the graph refers to the feature of local discontinuity< Strong > principle < / strong > Laplacian sharpening image is related to the mutation degree of the surrounding pixels of an image pixel, that is, it is based on the change degree of image pixels. We know that the first-order differential of a function describes where the function image changes, that is, increase or decrease; The second-order differential describes the speed of image change, rapid growth and decline or gentle growth and decline. Therefore, we can guess the transition degree of the pigment of the image according to the second-order differential. For example, the transition from white to black is relatively sharp. Or in the official words: when the gray level of the central pixel in the neighborhood is lower than the average gray level of other pixels in its field, the gray level of the central pixel shall be further reduced. When the gray level of the central pixel in the neighborhood is higher than the average gray level of other pixels in its neighborhood, the gray level of the central pixel shall be further improved, so as to realize the image sharpening processing< Strong > Application < / strong > using Laplace can enhance the details of the image and find the edge of the image. But sometimes the noise is also enhanced, so the image can be smoothed before sharpening. Let’s deduce the relationship between the second-order differential and pixels: first look at the first-order partial differential and the derived binary function differential:

$\begin{array}{l}&\frac{\partial f}{\partial x}=f(x, y)-f(x-1, y) \\&\frac{\partial f}{\partial y}=f(x, y)-f(x, y-1) \\&\nabla \mathrm{f}=\frac{\partial f}{\partial x}+\frac{\partial f}{\partial y}=2 f(x, y)-f(x-1, y)-f(x, y-1)\end{array}$

The first-order differential method can be used to detect the existence of edges.

Then the second-order differential method, that is, Laplace operator, can determine the position of the edge. (in some articles, the following formula is called < strong > Laplace mask center coefficient < / strong >)

$\nabla^{2} \mathrm{f}=4 f(x, y)-f(x-1, y)-f(x, y+1)-f(x+1, y)-f(x, y-1)$

A template matrix can be found:

$\begin{array}{ccc}0 & – 1 & 0 \\-1 & 4 & – 1 \\0 & – 1 & 0\end{array}$

This becomes a four neighborhood, which is the second-order differential method above

$\begin{array}{ccc}-1 & – 1 & – 1 \\-1 & 8 & – 1 \\-1 & – 1 & – 1\end{array}$

This is an eight neighborhood.

[note] it can be seen from the above two templates that if there is a white dot in a black plane, the template matrix can make the white dot brighter. Because the image edge is the region where the gray level jumps, the Laplace template is very useful for edge detection.

The representation of eight neighborhoods is:

$\begin{array}{r}\nabla^{2} \mathrm{f}=8 f(x, y)-f(x-1, y-1)-f(x-1, y)-f(x-1, y+1)-f(x, y-1) \\-f(x, y+1)-f(x+1, y-1)+f(x+1, y)-f(x+1, y+1)\end{array}$

Replace the calculated value with the pixel value at the original $(x, y)$to get a place similar to the boundary, and then get the sharpened image according to the following formula:

$\mathrm{g}(\mathrm{x})=\left\{\begin{array}{ll}\mathrm{f}(\mathrm{x}, \mathrm{y})-\nabla^{2} f(x, y), & \nabla^{2} f(x, y)<0 \\\mathrm{f}(\mathrm{x}, \mathrm{y})+\nabla^{2} f(x, y), & \nabla^{2} f(x, y) \geq 0\end{array}\right.$