图像直接滤波 opencv下的问题 显示为黑色

xavier_x 2013-04-30 02:36:09

#include "cv.h"
#include "highgui.h"

using namespace cv;
using namespace std;

Mat scr_img ;
Mat gray_img ,blur_img;

Mat InverseFliter();

Mat InverseFliter()
{

Mat padded;
int dft_h = getOptimalDFTSize(blur_img.rows);
int dft_w = getOptimalDFTSize(blur_img.cols);
copyMakeBorder(blur_img,padded,0,dft_h-blur_img.rows,0,dft_w-blur_img.cols,BORDER_CONSTANT,Scalar::all(0));
Mat planes[] = {Mat_<float>(padded) , Mat::zeros(padded.size(),CV_32F)};
Mat complexI;
merge(planes,2,complexI);
dft(complexI,complexI);
double a,b,c,d;
int height = complexI.rows;
int width =complexI.cols;
int ch = complexI.channels();
Mat H_Function = (Mat_<float>(dft_h, dft_w ));
Mat h_fuction;
for(int j=0;j <dft_h;j++)
{
uchar *H_ptr = H_Function.ptr<uchar>(j);
for(int i=0; i<dft_w ;i++)
{
//for(int k=0; k<ch;k++)
//{
if(i < 5 && j< 5)
{
H_ptr[i ] =0.04;
}
else
{
H_ptr[i] =0.0;
}
//}
}
}
Mat planes1[] = { H_Function , Mat::zeros(H_Function.size(),CV_32F)};
merge(planes1,2,h_fuction);

dft(h_fuction,h_fuction);
Mat dst_img;
dst_img.create(dft_h, dft_w, CV_64FC2);
for(int row=0; row <height;row++)
{
uchar *Scr_ptr =complexI.ptr<uchar>(row);
uchar *H_ptr1 = h_fuction.ptr<uchar>(row);
double *Dst_ptr = dst_img.ptr<double>(row);
for (int col = 0; col< width;col++)
{

a = Scr_ptr[col*ch];
b = Scr_ptr[col*ch +1];
c = H_ptr1[col*ch];
d = H_ptr1[col*ch+1];
if(c*c +d*d >1e-3)
{
Dst_ptr[col *ch] = (a*c +b*d)/(c*c + d*d);
Dst_ptr[col *ch +1] = (b*c-a*d)/(c*c+d*d);
}

}
}
idft(dst_img, dst_img); //或者 dft(dst_img,dst_img,CV_DXT_INVERSE_SCALE);

split(dst_img,planes1);
Mat idft_img2 = planes1[0];
return idft_img2;


int main()
{
scr_img = imread("lena.jpg",1);
if(scr_img.empty ())
{
cout<<"Miss the Image File"<<endl;
return -1;
}
cvtColor(scr_img,gray_img,CV_BGR2GRAY);
blur(gray_img,blur_img,Size(4,4));
Mat scr = InverseFliter();
//s_img.convertTo(blur_img,CV_8UC3,1,0);
imshow("window2",scr);
waitKey(0);
}


...全文
271 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
timidsmile 2013-07-22
  • 打赏
  • 举报
回复
卤煮用的函数窝都好不熟悉喔~~~ 习惯了用opencv C 了。。 mark下,我要 copy研究研究
xavier_x 2013-04-30
  • 打赏
  • 举报
回复
自己顶,纠结好久了

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧