[Digital image processing] frequency domain filter (opencv + vs2017)

Disclaimer: This article is a blogger original article, reproduced, please indicate the source https://blog.csdn.net/C2681595858/article/details/84487617

First, experimental design

Preparation before test: Fourier transform and inverse transform opencv example interpretation.

1, before filtering Preparation

  • An inverse Fourier transform of the original need to know the real part and an imaginary part, but after the Fourier transform image shows the amplitude spectrum, that is to say the frequency domain from the display image on the screen directly back into the airspace is done not (because it does not know the real and imaginary parts).
  • So in order to be able to perform inverse Fourier transform, we must hold intermediate values ​​forward Fourier transform, it is that the value of the real and imaginary components stored.
  • However, the direct use of the official method of the example, it will not work, because he is the first amplitude spectrum is calculated, and then the shift. However, our high-pass or low-pass filtering, more accustomed to using image shift (but image official example shift has not said real and imaginary part of a), so we must first respectively the real part and the imaginary part shift, and then filtered.
  • Function is designed: Since the real and imaginary parts are shifted in the same method, but the need to use two, it is possible to design a function that can be invoked directly transmitted parameters.
  • In order to make the program less confusing, we always follow during the transformation of a principle that once complexI is assigned not change the value of complexI. Meanwhile imat [2] is assigned from the beginning has been to keep the move, if you want to destroy the shift in time the change over, until it is no longer used.

2, function design

class FDF {
public:
	/*
	构造函数,可以直接传入文件名来创建
	*/
	FDF(string image_spa_in);

	/*
	如果创建对象时没有穿入文件名,可以后期设置文件名
	*/
	void setImage(string image_spa_in);

	/*
	*返回空域图像
	每次滤波时不会保存上次滤波的结果
	所以在每次滤波以后要及时调用该函数取得空域图像
	*/
	Mat getImageSpa();

	/*
	*返回频域图像
	每次滤波时不会保存上次滤波的结果
	所以在每次滤波以后要及时调用该函数取得频域图像
	*/
	Mat getImageFre();

	/*
	傅里叶变换,只需一开始调用一次,得到频域图像后结果会长期保存,无需多次调用
	*/
	void dft_();

	/*
	*傅里叶反变换
	每次对图像滤波结束以后可以用它来得到滤波后空域的图像
	*/
	void idft_();

	/*
	*下面是几种低通滤波器
	*/
	void ILPF(float d0);
	void BLPF(int n, float d0);
	void GLPF(float d0);

	/*
	*拉普拉斯滤波器
	*/
	void Laplacian();

	/*
	*这个函数用来设置频域图像
	*由于滤波操作是在复数(2通道Mat)上进行的,所以要显示频域图像的话首先要进行一些处理
	*/
	void setFreImg();//这个函数用来将各种滤波后的中间结果转变为频域图像存储在Image_fre中

	/*
	*添加噪音
	*/
	void addNoise();
private:
	Mat image_spa;//存放原始空域图像
	Mat complexI;//存放复数形式的图像
	Mat imat[2];//这个是提供给各种滤波的,是将complexI分开并移中后的结果
	Mat Image_fre;//存放滤波后频域的图像

	void splitAndCenter();//将complexI分开并移中后的存储到imat2[]中
	void center(Mat& imag);//移中
	
};
float dist(const float& a, const float& b, const float& c, const float& d);

Second, the experimental process

  • Design two private functions: void center(Mat& imag);void splitAndCenter();The first is responsible for the imag passed in crop and move, of course, also be used in the inverse transform of the canceled shift. The second member is responsible for private calls and dividing center complexI be shifted, the result is stored in imat [2], it is convenient for a variety of subsequent filtering operations.
  • void dft_();Fourier transform, while the intermediate results, the Fourier transform is not yet divided in the form of 2-channel results are stored in the private variable complexI facilitate the subsequent filtering operation.
  • void idft_();Inverse Fourier transform, responsible imat [2] to the spatial domain from the frequency and stores the result in the private variable image_spa.
  • Other functions are the corresponding filters, since the high pass filtering and low pass filtering the contrary, it is only the low-pass filtering, high pass filtering made Laplacian filter.

Third, the results analysis

  • The original image
    Here Insert Picture Description
    Here Insert Picture Description
  • Over the low-pass filtering
    Here Insert Picture Description
    Here Insert Picture Description
  • Butterworth filter
    Here Insert Picture Description
    Here Insert Picture Description
  • Gaussian filter
    Here Insert Picture Description
    Here Insert Picture Description
  • Laplacian filter
    Here Insert Picture Description
    Here Insert Picture Description
  • Add Noise
    Here Insert Picture Description
    Here Insert Picture Description

Guess you like

Origin blog.csdn.net/C2681595858/article/details/84487617