資源簡介
花了本人三天時間實現維納濾波對圖像進行復原,親測無誤,注意我是用的opencv靜態庫,你可能需要配置一下

代碼片段和文件信息
#include
#include
#include
#include
#include???????//存儲int型變量用32位
//#include
#include?
#define?max(xy)???(x)>=(y)?(x):(y)
#define?eps?2.22044604925031e-016;
#define?pi?3.1415;
using?namespace?std;
#define?SWAP(ab)?tempr=(a);(a)=(b);(b)=tempr
#?pragma?comment(linker?“/NODEFAULTLIB:atlthunk.lib“)
#?pragma?comment(linker?“/NODEFAULTLIB:LIBCMT“)
#?pragma?comment(linker?“/NODEFAULTLIB:MSVCRTD“)
BOOL?fourn(double?*?data/*psrc*/?unsigned?long?nn[]/*w*/?int?ndim/*2*/?int?isign);
double?CY_sign(double?cosphi);
void?CYmeshgrid(int?xmint?xnint?ymint?ynCvMat*?&XCvMat*?&Y);
void?CY_special(double?lendouble?thetaCvMat?*&h_last);
void?main(int?argc?char?argv[])
{
IplImage?*Gray1?=?cvLoadImage(“ceshi1.jpg“-1);
IplImage?*Gray?=?cvCreateImage(cvSize(256256)Gray1->depth1);
cvResize(Gray1GrayCV_INTER_CUBIC);
cvNamedWindow(“src“1);
cvShowImage(“src“Gray1);
int?lHeight?=?Gray->height;
int?lWidth?=?Gray->width;
int?lLineBytes?=?Gray->widthStep;
int?lw?=?1;
int?lh?=?1;
int?wp?=?0;
int?hp?=?0;
//保證離散傅里葉變換的寬度和高度為2的整數冪
while(lw*2?<=?lLineBytes)
{
lw?=?lw*2;
wp++;
}
while(lh*2?<=?lHeight)
{
lh?=?lh*2;
hp++;
}
//輸入退化圖像的長和寬必須為2的整數倍;
if(lw?!=?(int)lLineBytes)
{
return;
}
if(lh?!=?(int)lHeight)
{
return;
}
//用于做FFT的數組
//?指向源圖像倒數第j行,第i個象素的指針???
double?*fftSrc?*fftKernel?*laplacianKernel;
fftSrc?=?new?double?[lHeight*lLineBytes*2+1];
fftKernel?=?new?double?[lHeight*lLineBytes*2+1];
laplacianKernel?=?new?double?[lHeight*lLineBytes*2+1];
unsigned?long?nn[3]?=?{0};
nn[1]?=?lHeight;
nn[2]?=?lLineBytes;?
LPSTR?lpSrc;
unsigned?char?pixel;
double?len?=?30;
double?theta?=?0;
CvMat?*h_last;
CY_special(lenthetah_last);
int?h_row?=?h_last->height;
int?h_col?=?h_last->width;
for?(int?j?=?0;j? {
for(int?i?=?0;i? {
//?指向源圖像倒數第j行,第i個象素的指針???
lpSrc?=?(char?*)Gray->imageData?+?lLineBytes?*?j?+?i;
pixel?=?(unsigned?char)*lpSrc;
fftSrc[(2*lLineBytes)*j?+?2*i?+?1]?=?(double)pixel;
fftSrc[(2*lLineBytes)*j?+?2*i?+?2]?=?0.0;
laplacianKernel[(2*lLineBytes)*j?+?2*i?+?1]?=?0.0;
laplacianKernel[(2*lLineBytes)*j?+?2*i?+?2]?=?0.0;
if(i? {
float?h_value?=?CV_MAT_ELEM(*h_lastfloatji);
fftKernel[(2*lLineBytes)*j?+?2*i?+?1]?=?double(h_value);
}
else
{
fftKernel[(2*lLineBytes)*j?+?2*i?+?1]?=?0.0;
}
fftKernel[(2*lLineBytes)*j?+?2*i?+?2]?=?0.0;
}
}
laplacianKernel[(2*lLineBytes)*0+2*1+1]?=?1.0;
laplacianKernel[(2*lLineBytes)*1+2*0+1]?=?1.0;
laplacianKernel[(2*lLineBytes)*1+2*1+1]?=?-4.0;
laplacianKernel[(2*lLineBytes)*0+2*2+1]?=?1.0;
laplacianKernel[(2*lLineBytes)*2+2*1+1]?=?1.0;
//對源圖像進行FFT
fourn(fftSrcnn21);
//對卷積核圖像進行FFT
fourn(fftKernelnn21);
//對過濾器進行FFT;
fourn(laplacianKernelnn21);
????double?abcdefnorm1norm
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????6899712??2013-01-09?10:31??Least?Square\Debug\Least?Square.exe
?????文件?????345654??2013-01-09?10:31??Least?Square\Debug\Least?Square.exp
?????文件????7429508??2013-01-09?10:31??Least?Square\Debug\Least?Square.ilk
?????文件?????578936??2013-01-09?10:31??Least?Square\Debug\Least?Square.lib
?????文件???16722944??2013-01-09?10:31??Least?Square\Debug\Least?Square.pdb
?????文件???????4020??2013-01-09?10:30??Least?Square\Least?Square\ceshi1.jpg
?????文件???????1484??2013-01-09?09:15??Least?Square\Least?Square\ceshi2.jpg
?????文件???????1244??2013-01-09?09:46??Least?Square\Least?Square\ceshi4.jpg
?????文件???????7443??2013-01-09?09:59??Least?Square\Least?Square\ceshi5.jpg
?????文件???????4648??2013-01-09?10:13??Least?Square\Least?Square\ceshi6.jpg
?????文件???????8718??2013-01-09?10:31??Least?Square\Least?Square\Debug\BuildLog.htm
?????文件????????663??2013-01-09?10:09??Least?Square\Least?Square\Debug\Least?Square.exe.em
?????文件????????728??2013-01-09?10:09??Least?Square\Least?Square\Debug\Least?Square.exe.em
?????文件????????621??2013-01-09?10:31??Least?Square\Least?Square\Debug\Least?Square.exe.intermediate.manifest
?????文件??????87740??2013-01-09?10:31??Least?Square\Least?Square\Debug\Least?Square.obj
?????文件?????????65??2013-01-09?10:31??Least?Square\Least?Square\Debug\mt.dep
?????文件?????986112??2013-01-09?10:31??Least?Square\Least?Square\Debug\vc90.idb
?????文件?????528384??2013-01-09?10:31??Least?Square\Least?Square\Debug\vc90.pdb
?????文件???????9090??2013-01-09?10:31??Least?Square\Least?Square\Least?Square.cpp
?????文件???????4391??2013-01-06?14:11??Least?Square\Least?Square\Least?Square.vcproj
?????文件???????1411??2013-01-09?10:31??Least?Square\Least?Square\Least?Square.vcproj.chen-PC.Administrator.user
?????文件????????817??2013-01-08?18:03??Least?Square\Least?Square\yy2.jpg
?????文件????????902??2013-01-06?13:58??Least?Square\Least?Square.sln
????..A..H.?????12288??2013-01-09?10:27??Least?Square\Least?Square.suo
?????目錄??????????0??2013-01-09?10:31??Least?Square\Least?Square\Debug
?????目錄??????????0??2013-01-09?10:31??Least?Square\Debug
?????目錄??????????0??2013-01-09?10:31??Least?Square\Least?Square
?????目錄??????????0??2013-01-09?10:28??Least?Square
-----------?---------??----------?-----??----
?????????????33637523????????????????????28
............此處省略1個文件信息
評論
共有 條評論