資源簡介
用opencv編寫的維納濾波器 實現圖像去噪和圖像恢復
代碼片段和文件信息
#include“weina.h“
void?weina(IplImage?*dstGIplImage?*dstW)
{
?????double?k=0.01;???????????//winer濾波加權系數
?????double?R=5;??????????????//散焦退化函數散焦斑半徑
?????int?width?=dstG->width;?//讀取圖像寬度?
??int?height?=?dstG->height;?//讀取圖像高度
?//?獲取傅立葉變換的最佳尺寸(大于等于原先尺寸)
????int?dft_h?=?dstG->height;
????int?dft_w?=?dstG->width?;
?//獲取退化函數h
?double?*h=(double?*)malloc(sizeof(double)*width*height);
?????memset(h0height*width);
?????CvMat*?image_hre?=?cvCreateMat(?height?width?CV_32FC1?);
???? for(int?i=0;i ?for(int?j=0;j ?{
?double?t=pow(1.0*i2)+pow(1.0*j2);
?if(t ????????????????h[j*width+i]=1.0/(3.14*R*R);
?else
????????????????h[j*width+i]=0;
?????????????image_hre->data.fl[j*image_hre->cols+i]=h[j*width+i];
?}
??//對退化函數h進行傅里葉變換
????CvMat*?image_him?=?cvCreateMat(?dft_hdft_w?CV_32FC1);
CvMat*?image_Cp?=?cvCreateMat(?dft_h?dft_w?CV_32FC2);
????CvMat*?image_dst?=?cvCreateMat(?dft_h?dft_w?CV_32FC2);
????cvZero(?image_him?);
????cvMerge(?image_hre?image_him?NULL?NULL?image_Cp?);
????cvDFT(?image_Cp?image_dst?CV_DXT_FORWARD?dstG->height?);
????cvSplit(?image_dst?image_hre?image_him?0?0?);
???
????//得到模糊圖像g的傅里葉變換
????CvMat*?image_gre?=?cvCreateMat(?dft_hdft_wCV_32FC1);
????CvMat*?i
- 上一篇:實驗3 C語言實現RC4加密算法報告
- 下一篇:幀間差分方法
評論
共有 條評論