Grayscale image--Introduction to frequency domain filtering

Source: Internet
Author: User

Study Dip 25th Day

reproduced please indicate the source of this article: Http://blog.csdn.net/tonyshengtan, Welcome to reprint, found that the blog is reproduced in some forums, the image can not be normal display, unable to express my views, to this expression is very dissatisfied. Some sites reproduced my blog, very happy is that they write something more people see, but not happy is this paragraph was removed, also did not indicate the source of reprint, although this does not have the copyright protection, but the feeling is not very good, out of respect for the author's labor, reproduced please indicate the source!!!!

The opening crap . These two days wrote a frequency-domain filter code, and found a bug in the previous blog code, the cause of the bug is that one-dimensional storage of two-dimensional matrix row width and column length is written back, and the test is not measured out, it seems that the test is necessary, but also learned the next use of GitHub, managed code, Because it is a side dish, the managed HelloWorld is not ashamed, the frequency domain filter intends to write two to three articles, then ends, carries on the next big problem research. The main knowledge frame of frequency domain filter has been made a structure diagram, completely personal understanding, if have the theoretical question, please point out in time:
frequency Domain Filtering BasicsThe most important theoretical basis for spatial filtering and time-domain filtering is that the high frequency portion of the frequency domain corresponds to the steep detail in the airspace, while the low frequency portion of the frequency domain corresponds to the flat area of the spatial change of the surface, in order to get a smooth or steep part, we think of the frequency domain filter, In the airspace in the details and non-detailed extraction and definition of the frequency domain is not so direct and clear, through the frequency domain of the laboratory, you can draw a lot of different problems, special filters, and then convert it to the airspace, generate small templates, using convolution operations to complete the rapid filtering, to achieve our goal. Basic relationship:
Yes, Ice ice and sister Feng is a filter! (This is, no such filter, do not imitate 0.0)Our basic principle is that the high frequency corresponds to the steep part of the change, and the low frequency corresponds to the slow part. Low frequency and high frequency in the frequency domain with digital measurement, filter on the frequency domain of the number of different degrees of enhancement or suppression, after the inverse transformation, to obtain the desired image, the frequency domain filter must be in the frequency domain about the origin of symmetry, or the inverse of the symmetric part of the frequency of the transformation will be the original image produced artifacts. the only input and filter that affect the filter effect in the frequency domain, if the DfT and filter are directly carried out for the unhandled input, we can see the mathematical effect:The convolution theorem shows that for the convolution of the 3x3 two matrices A and B, it should be equal to the DfT of a and the DfT of B for phase multiplication (the meaning of the phase multiplication is c,c (x, y) =a (x, y) *b (x, y), rather than the normal matrix multiplication, for the result of A and b pairs of phases. Then the IDFT transformation can be obtained and the spatial convolution result, but we get the result:
Clear All;clc;a=[1 2 1;1 1 1; 0 2 1];fa=fft2 (a); b=[3 2 1;3 1 1; 2 0 1];fb=fft2 (b); Temp=eye (3); for R=1:3 for    c=1:3        temp (r,c) =fa (r,c) *FB (r,c);    ENDENDRES=IFFT2 (temp);

The convolution equals the result:by our hand calculation, we find that the result is not right, what is the reason why, we do not say why, we extend the matrix with 0 to 5x5:
Clear All;clc;a=[1 2 1 0 0;1 1 1 0 0;0 2 1 0 0;0 0 0 0 0;0 0 0 0 0];fa=fft2 (a); B=[3 2 1 0 0;3 1 1 0 0;2 0 1 0 0;0 0 0 0 0;0 0 0 0 0];fb=fft2 (b); Temp=eye (5); for R=1:5 for    c=1:5        temp (r,c) =fa (r,c) *FB (r,c);    ENDENDRES=IFFT2 (temp);

Convolution equalsYes, look at the red box, and we use the written calculation of the 3x3 results the same;The reason is that if a signal with a finite width of a is used for convolution of a window with a width of B, the result would be a signal with a width of a+b-1, but if the signal width is a but the period is a, the head of the signal tail and the next cycle is next to each other, Then the end of the convolution when the signal will be entangled with the head of the signal, so that the results of the head and tail are contaminated, the middle part remains correct, but if the signal is relatively short, like the above 3x3 words are completely contaminated. but the signal above is not periodic, but the finite width, the problem is in the DFT, because the DFT to expand the signal, and is a periodic expansion, the DFT signal is actually this:
so the two signals of the DfT are cycles rather than the signals we've entered before, so there 's a entanglement.

to avoid this problem, it is simple to use 0 to fill two matrices , and then to get the correct convolution results after being filled into 5x5. filter characteristics, the filter is the real part of the Fourier spectrum and the imaginary part of the ratio to enhance or suppress, that is, the Fourier spectrum after the filter, the phase is unchanged, the main reason mentioned before, is a spectral phase angle determines the main structural characteristics of the picture, so if you change the phase angle, the picture will create a huge problem , so the filter used is 0 phase shifted, but if you use a non-0 phase shift You can get results for other purposes, such as making a picture unrecognizable. for the ideal filter, we must consider its expansion problem, because the off-line ideal filter is the frequency domain, its expansion should be in the airspace, and the idft of the ideal filter is not limited in airspace but an infinite sinc function, which is then filled after the stage, Return frequency domain After the fill filter will produce a serious ringing phenomenon, here our method is only to fill the image, filled to the original 4 times times the size of the picture, and then use the size of the filter to reduce the winding problem, while making the problem simple, but only to alleviate the winding problem, ringing problem still exists.     A is a frequency domain one-dimensional ideal filter, B is the spatial waveform after idft, C is filled, d is the result of the DfT after fillingLet me explain the ringing phenomenon, an official explanation:

The ringing effect (ringingeffect) is one of the many factors that affect the quality of reconstructed images, and its typical manifestation is the oscillation of the Gibbs (Gibbs) distribution in the neighborhood where the intensity of the image changes drastically (satisfying the given constraints and the most entropy distribution). In the image blind restoration, the ringing effect is an important problem, which seriously reduces the quality of the reconstructed image and makes it difficult to follow up the restoration image. The ringing effect is caused by selecting inappropriate image model in image restoration, and if the point diffusion function is not accurate in image restoration, it is another reason to cause the ringing effect of the restoration result, especially when the point diffusion function is larger than the real point diffusion function size, the ringing phenomenon is more obvious. , the direct cause of ringing effect is the loss of information in the process of image degradation, especially the loss of high frequency data.

official explanation may not understand, in the frequency domain ideal filter case, in fact, is the sinc function produced, only consider A and b,a is the frequency domain ideal filter, B is the corresponding filter in the airspace, the image if and B convolution, the results will inevitably produce similar waves of noise, image edge would produce jitter, The edge becomes wider, this is the ringing effect, we observe the ideal filter with different cutoff frequency and its idft effect:It can be seen that the wider (cut-off frequency) of the filter in the frequency domain of the more obvious ringing, on the contrary, the narrower the filter, the greater the spatial ringing effect. frequency domain filtering process frequency domain filtering process: Because we want to get the image, the input is an image, the output is also an image, this process is called image processing, if the output of the spectrum or other, we call image analysis, the main parameters of the filter is the type and cutoff frequency. Let's take a look at the full computational process of the algorithm:
Original:
Airspace Fill:fill the picture with 0 to get a new image of 4 times times the original
Spectral centeringThis is to match the filter, because the filter is generally designed to be low-frequency in the middle, and the pattern around the high frequencyDFT:over to the frequency domain
Design Filtersfir Filter, a finite-length unit impulse response filter, also known as a non-recursive filter, which is used in image processing to produce a Gaussian low-pass filter:for phase multiplication:
IDFT:To reconstruct the filter result into an image
airspace Cancel Fill:restores the filled image
Code:
#include "filter.h" static void Showfilter (double *filter,int width,int height) {iplimage *show=cvcreateimage (cvsize (WI    DTH, height), 8, 1); for (int i=0;i<width;i++) for (int j=0;j

spatial filtering and frequency domain filtering

the spatial and frequency domain bridge is the Fourier transform, and the link is the convolution theorem, for the frequency domain characteristic, we regard it as a laboratory, carries on the experiment and produces the small filter template, the small filter template carries on the circulation convolution to the airspace image, obtains the result which we want, The spatial small template is mostly odd-sized (3x3,5x5), its computational complexity is low, the process is simple, the time is short, this is the answer to the interview question mentioned earlier, if I had this process to tell the interviewer clearly, I am now an image worker.

Summary

This is the basis of the frequency domain filter, the next thing is to design filters, to meet the different problems, with the foundation, design filters will be their own play.


Grayscale image--Introduction to frequency domain filtering

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.