MATLAB Digital Image processing (c) Spatial filtering

Source: Internet
Author: User

Filtering is a common technique in image processing, which can sharpen image, blur image, remove noise, enhance image and so on. Only spatial filtering is spoken here, and the frequency domain filter will be spoken later.
Spatial filtering : In simple terms, it is a template (3x3 matrix, 5x5 matrix ...). Usually odd) buckle in the image, with each element in the template to the corresponding pixels in the range of the mathematical operation, the resulting value is assigned to the template center point corresponding.

Classification: linear Spatial filtering, non-linear spatial filtering.

linear Spatial Filtering : Filtering based on the computed product and (linear operation). For example, New=a*g1+b*g2+c*g3+d*g4+e*g5, which is a linear operation.

Nonlinear Spatial filtering : filtering based on a mechanism, such as median filtering, selects the median of the image pixels within the template range and assigns the pixels corresponding to the center point. linear Spatial Filtering

There is a need to understand two concepts: correlation and convolution. These two are the same as all previous spatial filters in a specific operation. The difference between the two operations is that the convolution rotates the template 180 degrees (inverse, clockwise) before the operation. Convolution and related specific concepts are easy to confuse people, here only the specific application, only need to know how to calculate the can.

Operation Process:

Related : R5 (center pixel) =R1G1 + r2g2 + r3g3 + r4g4 + r5g5 + r6g6 + R7g7 + r8g8 + r9g9
Convolution (template also known as core, rotated 180 degrees):
R5 (center pixel) =r1g9 + R2g8 + R3g7 + r4g6+ R5g5 + r6g4 + r7g3 + r8g2 + r9g1

The function IMFilter () is provided in MATLAB for filtering operations.

G=imfilter (f,w, ' replicate ')

F is the image to be processed, W is the filter, and the replicate specifies that it is extended by copying values outside the bounds of the image. MATLAB provides a function fspecial (), generating various types of two-dimensional linear filter, the function is as follows.

W=fspecial (' type ' parameters)

Type of the filter, parameters, optional parameters.

Let's run it down and see how it's applied and how it works.

  F=imread (' 1.jpg ');
  Imshow (f)
  w=fspecial (' average ');%3x3 (default) uniform filter
  f1=imfilter (f,w, ' replicate ');
  Figure,imshow (F1)

Nonlinear Spatial filtering

Nonlinear spatial filtering: Based on the nonlinear operation of pixels in the neighborhood of the design filter guard, for example, the response of each center point is equal to the maximum pixel value in the neighborhood.

For nonlinear spatial filtering, the operation is performed because of too many rules such as: taking maximum, minimum, median, or defining a nonlinear function. Only the most famous and commonly used median filter is described here.
Median filtering is often used to remove noise, especially salt and pepper noise. The specific application is as follows

F=imread (' 1.jpg ');
F=imnoise (f, ' salt & Pepper ', 0.2);
G=MEDFILT2 (f);
G=MEDFILT2 (F, ' symmetric ');
Subplot (1,2,1); Imshow (f); title (' Noise pollution ');
Subplot (1,2,2); Imshow (g); title (' Median filter ');

Note: MATLAB provides a function parameter manual (Help), click. You can query the usage of various functions. It's pure English, of course. Have seen a sentence before, want to learn computer, English must be good to learn , or you may not even a functional prototype of the English help document can not understand.

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.