圖像出增強之銳化---拉普拉斯銳化


(1)拉普拉斯理論

(2)拉普拉斯算子

(3)拉普拉斯實現

--------------------------------------

(1)拉普拉斯理論

  http://course.cug.edu.cn/pic_ana/wangluoketang/Chapter04/4.2.2.htm

http://blog.sina.com.cn/s/blog_6163bdeb0100h1xf.html

更復雜些的濾波算子一般是先利用高斯濾波來平滑,然后計算其1階和2階微分。由於它們濾除高頻和低頻,因此稱為帶通濾波器(band-pass filters)。

在介紹具體的帶通濾波器前,先介紹必備的圖像微分知識。

1 一階導數

連續函數,其微分可表達為image ,或image                         (1.1)

對於離散情況(圖像),其導數必須用差分方差來近似,有

                                   image,前向差分 forward differencing                  (1.2)

                                   image ,中心差分 central differencing                     (1.3)

實例:技術圖像x方向導數

1
2
I = imread( 'coins.png' ); figure; imshow(I);
Id = mipforwarddiff(I, 'dx' ); figure, imshow(Id);

      image image

    原圖像                                                   x方向1階導數

 

2 圖像梯度(Image Gradient)

圖像I的梯度定義為image  ,其幅值為image 。出於計算性能考慮,幅值也可用image 來近似。

Matlab函數

1)gradient:梯度計算

2)quiver:以箭頭形狀繪制梯度。注意放大下面最右側圖可看到箭頭,由於這里計算橫豎兩個方向的梯度,因此箭頭方向都是水平或垂直的。

實例:仍采用上面的原始圖像

1
2
3
4
5
I = double (imread( 'coins.png' ));
[dx,dy]=gradient(I);
magnitudeI=sqrt(dx.^2+dy.^2);
figure;imagesc(magnitudeI);colormap(gray);%梯度幅值
hold on ;quiver(dx,dy);%疊加梯度方向

        image image

                         梯度幅值                                   梯度幅值+梯度方向

 

3 二階導數

對於一維函數,其二階導數image ,即image 。它的差分函數為

                                 image                  (3.1)

 

3.1 普拉斯算子(laplacian operator)

3.1.2 概念

拉普拉斯算子是n維歐式空間的一個二階微分算子。它定義為兩個梯度向量算子的內積

                           image       (3.2)

其在二維空間上的公式為:    image                (3.3)

 

對於1維離散情況,其二階導數變為二階差分

1)首先,其一階差分為image

2)因此,二階差分為

           image

3)因此,1維拉普拉斯運算可以通過1維卷積核image 實現

 

對於2維離散情況(圖像),拉普拉斯算子是2個維上二階差分的和(見式3.3),其公式為:

image   (3.4)

上式對應的卷積核為

                       image

常用的拉普拉斯核有:

                      image

3.1.2 應用

拉普拉斯算子會突出像素值快速變化的區域,因此常用於邊緣檢測。

 

 

Matlab里有兩個函數

1)del2

計算公式:image ,image  

2)fspecial:圖像處理中一般利用Matlab函數fspecial

h = fspecial('laplacian', alpha) returns a 3-by-3 filter approximating the shape of the two-dimensional Laplacian operator.
The parameter alpha controls the shape of the Laplacian and must be in the range 0.0 to 1.0. The default value for alpha is 0.2.

(2)拉普拉斯算子

image

 

 第一個算子核可以用求導查分的出來的系數,是四鄰域的,第二個暫時還不曉得怎么的出來的,是8鄰域,帶斜面效果比第一個好些!

add! 后面發現一篇文章解釋了這個推導過程,還是不明白;

//

對角線方向也可以加入到離散拉普拉斯變換的定義中.只需在式(3.7.4)中添入兩項,即兩個對角線方向各加一個。每一個新添加項的形式與式(3.7.2)或式(3.7.3)類似,只是其坐標軸的方向沿着對角線方向。由於每個對角線方向上的項還包含一個-2f(x,y),所以,現在從不同方向的項上減去的總和是-8f(x,y)。執行這一新定義的掩模如圖3.39(b)所示。這種掩模對45o增幅的結果是各向同性的。圖3.39所示的另外兩個掩模在實踐中也經常使用。這兩個掩模也是以拉普拉斯變換定義為基礎的,只是其中的系數與我們在這里所用到的符號相反而已。正因如此,它們產生等效的結果,但是,當拉普拉斯濾渡后的圖像與其他圖像合並時(相加或相減),則必須考慮符號上的差別。 

上面的方程式在下面

http://blog.sina.com.cn/s/blog_6e7e94bc0100o9lr.html

http://www.cnblogs.com/pegasus/archive/2011/05/20/2051780.html

http://www.math.zju.edu.cn/cagd/resources/thesis/MasterThesis_FangHuilan.pdf 網格曲面上離散曲率計算方法的比較與研究 浙江大學數學系的碩士論文,可以挖據資源哦 貌似小豬的畢設就是這個題目

//

(3)拉普拉斯實現

基於模板的:

 /**************************************
********************************
*
* 函數名稱:
*     LapTemplate(int inputH, int
inputW, int inputX0, int inputY0, float
*     pTemplate, float fCoef)
*
* 參數:
*     int inputH-模板的高度
*     int inputW-模板的寬度
*     int inputX0-模板的中心元素X坐標
*     int inputY0-模板的中心元素Y坐標
*     float *pTemplate-指向模板數組的指針
*     float f-模板系數
*
* 返回值:
*     void
*
* 說明:
*     該函數用指定的模板(任意大小)來對
圖像進行操作,參數inputH指定模板
*     的高度,參數inputW指定模板的寬度,
參數inputX0和iinputY0指定模板的中心
*     元素坐標,參數pTemplate指定模板元素,f指定系數
*     拉普拉斯銳化
***********************************
***********************************/
void CImgEnhance::LapTemplate(int
inputH, int inputW, int inputX0, int
inputY0, float *pTemplate, float f)
{
unsigned char *pSrc, *pDst;
int  i,j,k,l;
float value;

if(m_pImgDataOut != NULL)
{
delete []m_pImgDataOut;
m_pImgDataOut = NULL;
}
 int lineByte = (m_imgWidth *
m_nBitCount / 8 + 3) / 4 * 4;

if(m_nBitCount != 8)
{
AfxMessageBox("只能處理8位灰度圖像!");
return ;
}
//創建要復制的圖像區域
m_nBitCountOut = m_nBitCount;
int lineByteOut = (m_imgWidth *
m_nBitCountOut / 8 + 3) / 4 * 4;
if (!m_pImgDataOut)
{
m_pImgDataOut = new unsigned char
[lineByteOut * m_imgHeight];
}

int pixelByte = m_nBitCountOut / 8;
for(i = 0; i < m_imgHeight; i++){
for(j = 0; j < m_imgWidth * pixelByte; j++)
*(m_pImgDataOut + i * lineByteOut + j)
= *(m_pImgData + i * lineByteOut + j);
}

//行處理
for (i = inputY0; i < m_imgHeight -
inputH + inputY0 + 1; i++)
{
//列處理
for (j = inputX0; j <m_imgwidth <br="" -="">inputW + inputX0 + 1; j++)
{
//指向新DIB第i行第j列像素的指針
pDst = m_pImgDataOut + lineByte *
(m_imgHeight -1 - i) + j;

value=0;
//計算
for (k = 0; k < inputH; k++)
{
for (l = 0; l < inputW; l++)
{
pSrc = m_pImgData + lineByte *
(m_imgHeight - 1 - i + inputY0 - k)+ j - inputX0 + l;
//計算加權平均
value += (*pSrc) * pTemplate[k * inputW + l];
}
}
//乘以系數
value *= f;
//取結果的絕對值
value = (float)fabs(value);
if (value > 255)
{
*pDst = 255; 
}
else
{
*pDst = (unsigned char)(value+0.5);
}
}
}
}

http://book.51cto.com/art/200808/84592.htm c++實現

http://dsqiu.iteye.com/blog/1638589

http://www.xuebuyuan.com/1050504.html

http://blog.csdn.net/jia20003/article/details/16369143 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM