图像直接滤波 opencv下的问题 显示为黑色
#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);
}
...全文
相关推荐
椒盐噪声和中值滤波.pdf
随机选择的像素坐标 `(i, j)` 被设置为255(白色)或0(黑色),对于彩色图像,所有三个通道(BGR)都被设置为相应的值。最后,处理后的图像被显示出来,可以看到椒盐噪声对原始图像的显著影响。
opencv分离RGB三通道
**图像去噪**:在单个通道上应用降噪算法,如中值滤波或高斯滤波,可能比直接在彩色图像上处理效果更好。
椒盐噪声与中值滤波[源码]
为了处理这一问题,开发了一种名为中值滤波的去噪技术,其作为一种非线性滤波方法,在去除图像中的脉冲噪声,特别是椒盐噪声方面显示出了良好的性能。
用c++读取灰度图像.txt
如果你遇到任何问题,或想要了解更多关于图像处理的知识,可以查阅OpenCV的官方文档和其他相关的C++图像处理教程。
C++OpenCV3源代码blur函数用法
**边界处理**:当模糊核的一部分超出图像边界时,需要选择合适的边界处理方式,以避免出现黑色边缘等问题。3.


图形处理/算法
