Current location - Recipe Complete Network - Diet recipes - What are the filters that come with matlab?
What are the filters that come with matlab?
1 linear smoothing filter

Using MATLAB to realize the program of suppressing noise by regional average method;

I = im read(' c4.jpg ');

Subplot (23 1)

Imshow (1)

Title ("Original Image")

I = RGB 2 gray(I);

I 1=imnoise(I,' salt & pepper', 0.02);

Subplots (232)

imshow(I 1)

Title ("Image with Salt and Pepper Noise")

k 1 = filter 2(f special(' average ',3),I 1)/255; % 3*3 Template smoothing filtering.

k2=filter2(fspecial('average ',5),I 1)/255; % for 5*5 template smoothing filter k3 = filter2 (fspecial ('average', 7), I1)/255; % 7*7 template smooth filtering.

k4=filter2(fspecial('average ',9),I 1)/255; % 9*9 template smooth filtering.

Subplot (233), im show (k1); Title ('3*3 template smooth filtering');

Subplots (234), IM Show (K2); Title ('5*5 template smooth filtering');

Subplots (235), IM Show (K3); Title ('7*7 template smooth filtering');

Subplots (236), IM SHOW (K4); Title ('9*9 Template Smooth Filtering');

2. Median filter

The program of median filtering with MATLAB is as follows:

I = im read(' c4.jpg ');

I = RGB 2 gray(I);

J=imnoise(I,' salt & pepper', 0.02);

Subplot (23 1), im show (I); Title ("original");

Subplot (232), im show (j); Title ('Add salt and pepper noise image');

k 1 = medfilt 2(J); % 3*3 template median filtering.

k2=medfilt2(J,); % for 5*5 template median filtering.

k3=medfilt2(J,); Median filtering of% 7*7 template.

k4=medfilt2(J,); Median filtering of% 9*9 template.

Subplot (233), im show (k1); Title ('3*3 template median filtering');

Subplots (234), IM Show (K2); Title ('5*5 template median filtering');

Subplots (235), IM Show (K3); Title ('7*7 template median filtering');

Subplots (236), IM SHOW (K4); Title ('9*9 template median filtering');

3 state statistical filter: ordfilt2 2 function

Y = ordfilter 2 (x, order, domain)

Replace each element in x with an ordered element in the neighborhood ordered set specified by a non-zero element in the domain. The domain is a matrix containing only 0 and 1, and 1 only defines the neighborhood of the filtering operation.

Y = ordfilter 2 (x, order, domain, s)

S is as big as domain, and the value of S corresponding to the non-zero value of domain is used as additional compensation.

Two-dimensional adaptive denoising filter: Wiener 2 function

The Wiener2 function estimates the local mean and variance of each pixel, which is used as follows:

J=wiener2(I, [M N], noise)

Using the mean and deviation of local images in the neighborhood of M×N size, the image I is filtered adaptively.

[J, noise ]=wiener2(I, [M N])

Before filtering, estimate the energy of additional noise.

5. Specific area filtering

The ROI filter 22 function provided in MATLAB image processing toolbox is used to filter specific areas, and its syntax format is:

J=roifilt2(h,I,BW)

Its function is to use filter H to filter the area selected by binary mask BW in image I. ..

J=roifilt2(I,BW,fun)

J=roifilt2(I,BW,fun,P 1,P2,…)

Its function is to perform a function operation fun on the area selected by the binary mask BW in the image I, where fun is a character string describing the function operation, and the parameters are P 1, P2,... The returned pixels of the image J in the selected area are the results of interesting operations of the image I, and the remaining pixel values are the original values of I. ..

Example: List of programs used to sharpen and filter the specified area:

I = im read(' eight . TIF ');

c =[222 272 300 272 222 194];

r =[2 1 2 1 75 12 1 12 1 75];

BW=roipoly(I,c,r);

h = f special(' unsharp ');

J=roifilt2(h,I,BW);

Subplots (1, 2,1); Imshow (1);

Subplots (1, 2, 2); imshow(J);

The running results show that the coin in the upper right corner has changed, while other coins remain unchanged.