Grayscale image--Spatial filtering basics: convolution and correlation

Source: Internet
Author: User

Study Dip 28th 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!!!!

Article code is hosted, Welcome to co-development:Https://github.com/Tony-Tan/DIPpro

The opening crap. nonsense began, the blog has been written to the 28th article, but the book has been looked at for two months, every day although very tired, but the feeling is a lot of harvest, one is to feel that they find the way, learning Foundation is very boring, because will not directly make the result, no sense of accomplishment, but look back to write the blog and code, Feel really improved, a lot of masters are also caught by the boss to do the image of the project, some people do not know what is, is learning programming, find a paper, grabbed OpenCV a meal to find Daniel for advice, and finally made a result, in fact, before I was so, made things after feeling a lot of harvest, but also a sense of accomplishment, But now look at a bit of castles in the ground, like a lot of people do a lot of image projects, but even the basic convolution, correlation, smoothing, sharpening are said not understand, they can also work very well, but the foundation is not very familiar with, more people do the original intention of the image is not a hobby, but simple work, or passive learning. Interest is the best teacher, fortunately, although every day work a day, I still have a passion to learn so long, and enthusiasm is more high. crosstalk Four subjects, said learn to sing, sing is the peace lyrics, but many people will not sing the peace lyrics, because that thing is very dull and difficult, and now no one requires you to learn all four lessons to post, so, now crosstalk is not good, not market downturn, is not enough, why Guo Degang can sell tickets, Why more than 10 years ago old Guo Eat rice also insisted, he later said, is love this line. Similarly, the basis of the image is very complex, comprehensive disciplines, linear algebra, probability theory, calculus, signal and system, digital signal processing, number theory and so a lot of knowledge, if it is true love, slowly, a little bit of learning solid, there will be a useful, although the company to master Dr. To do the image algorithm, but I believe, as long as the Learn in depth, someone will want myIntroduction to Spatial filtering Basics      today is a bit more nonsense, because the content is not many, the concept of filtering is in fact the frequency domain concept, that is, the signal frequency processing, above or below the cutoff frequency will be killed, or band pass band limit, there is a high-pass filter, low-pass filter. The multiplication of the frequency domain corresponds to the convolution of the time domain, therefore, the spatial filter (also called convolution kernel, spatial mask, core, template, window, etc.) and the convolution of the image can achieve the same or similar effect in the frequency domain, so we have to say the first image of the spatial convolution, it is worth noting that the spatial filter only linear filter and frequency domain pair should be correlated , nonlinear filters cannot be implemented in frequency domain. The spatial filter consists of:
    1. A neighborhood (typically a rectangle centered at a point)
    2. The adjacent domain to do the specified operation, the result is assigned to the center of the neighborhood, in particular, the assignment to the adjacent center is not the original, but the result, because the results of this step will not affect the next calculation, so the original image can not be changed
If the linear operation is performed, the corresponding operation can be found in the frequency domain, and if the nonlinear operation is used, the frequency domain does not correspond. The general mask uses an odd x odd size because the center is an integer coordinate:The linear calculation is as follows, W is the template and F is the image:
:
similar to the convolution calculation, called correlation, the relevant template from the image, the calculation of the template and the image of each location corresponding to the product and sum, assigned to the central location, convolution similar but to the template rotation 180 °, if the template is stored in linear, simple cooking is the array inverted, and finally become the first. For pixels at the edge of the image, the convolution cannot be covered by using a peripheral 0 method. take a screenshot to explain the above, or read the previous blog about convolution's understanding:

There are several points to note:
    1. A function of the displacement in the case of convolution or correlation
    2. The filter template w is related to only one of the 1 other functions that are 0, resulting in a rotated 180° copy, which is called a discrete unit impulse.
    3. If the template is symmetric about the origin, then the correlation and convolution results are the same.
    4. Use convolution when filtering, correlation can be used for template matching
    5. Convolution is the basis of linear system calculation
Next is the definition of convolution template, previously said in the frequency domain, a linear template can be the frequency domain design and then ifft to the airspace, generate small template, there is directly in the airspace design, template coefficients determine the purpose of the template, for the linear template, the only thing to do is multiply after the sum, Therefore, the calculation method stipulates that only a coefficient can be designed later. For example, use a two-Gaussian function to generate a template. after a filter is defined in the airspace, it is generally necessary to observe whether there are other frequencies in the frequency domain, for example, for a smoothing filter, we should observe its frequency domain characteristics and whether there is a sidelobe in the High frequency section. For a discrete template, however, a sidelobe is created as long as there is truncation.
Spatial filtering and frequency domain comparison Here we only compare the time complexity of the algorithm, because I once said an interview question, why use a spatial filter template, rather than using frequency domain filtering. The calculation process of frequency domain and calculation amount of algorithm are given:
The final calculated amount is to remove the assignment operation, the result: (4+8log2n) *n^2and spatial convolution (related) if not optimized, using the most common algorithm, the time complexity is n^2*m^2 (where M is the window width), so when m^2< (4+8log2n), the frequency domain filtering speed has no advantage, the main point is to expand the image after the introduction of high-frequency interference, observe
The edge of the filled image will introduce high-frequency component, so that the frequency domain filter has high frequency interference for one week.Original:
It's a white picture of a 512x512.after using Gaussian high-pass processing:
the surrounding white is the result of the high-frequency component being left behind. In particular, if the null preprocessing is high-pass, changing the surrounding fill strategy (such as copying the edges) will not have this effect. SummarizeSummary, the airspace processing will occupy most of the processing, and the frequency domain is more suitable for analysis, like MATLAB is generally used as a simulation and experimental algorithm, the real project in general to use c,c++ these tools, so, each has various uses, analysis and engineering, are important applications

Grayscale image--Spatial filtering basics: convolution and correlation

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.