Detailed explanation of the usage of fspecial function in matlab for image processing

1. Basic calling format of fspecial() function

By typing in the command line window of matlab:help fspecial, you can view the following instructions:

fspecial - Create predefined 2D filters
This MATLAB function creates a two-dimensional filter h of the specified type. Some filter types have optional additional parameters
number, as shown in the following syntax. fspecial returns h in the form of a correlation kernel suitable for imfilter.
    h = fspecial(type)
    h = fspecial('average',hsize)
    h = fspecial('disk',radius)
    h = fspecial('gaussian',hsize,sigma)
    h = fspecial('laplacian',alpha)
    h = fspecial('log',hsize,sigma)
    h = fspecial('motion',len,theta)
    h = fspecial('prewitt')
    h = fspecial('sobel')

To summarize, the fspecial function has three syntax formats:
(1)h=fspecial(type)
(2)h=fspecial(type,para)
(3)h=fspecial(type,para,sigma)
intype is used to specify the filter type, para is used to add additional parameter information to the specific filter type, and sigma is used to represent the standard deviation of the filter. The unit is pixels and the default value is 0.5.

2. Filter type description

1、‘average’

‘average’ represents average filtering, h = fspecial(‘average’,hsize) generates an average filter, and the parameter hsize represents the template size, which is 3*3 by default.

2、‘disk’

‘disk’ represents circular area mean filtering. h = fspecial(‘disk’,radius) generates a circular area mean filter. The parameter radius represents the area radius and the default is 5.

3、‘gaussian’

‘gaussian’ represents Gaussian low-pass filtering. h = fspecial(‘gaussian’,hsize,sigma generates a Gaussian low-pass filter. The parameter hsize represents the template size. The default is 3*3. sigma is used to represent the standard deviation of the filter. The unit is pixels and the default value is 0.5.

4、‘laplacian’

‘laplacian’ represents the Laplacian operator, h = fspecial(‘laplacian’,alpha) generates a Laplacian filter, the parameter alpha is used to control the shape of the operator, the value range is [0 1], the default value is 0.2.

5、‘log’

‘log’ represents the Laplacian-Gaussian operator, h = fspecial(‘log’,hsize,sigma) generates a Laplacian-Gaussian filter, the parameter hsize represents the template size and the default is 3*3, sigma is used to represent the filter The standard deviation of , in pixels and the default value is 0.5.

6、‘motion’

‘motion’ represents the motion blur operator, h = fspecial(‘motion’,len,theta) generates a motion blur filter. The parameters len and theta represent that the camera object has moved len pixels counterclockwise at the angle of theta. The default value of len is 9, the default value of theta is 0.

7、‘prewitt’

‘prewitt’ is the prewitt operator, used for edge enhancement, no parameters.

8、 ‘sobel’

‘sobel’ is the sobel operator, used for edge extraction, no parameters.

3. Application examples of fspecial() function

img = imread('football.jpg');
I1=imfilter(img,fspecial('average'),'replicate','same');
I2=imfilter(img,fspecial('disk',5),'replicate','same');
I3=imfilter(img,fspecial('gaussian',5,0.5),'replicate','same');
I4=imfilter(img,fspecial('laplacian',0.2),'replicate','same');
I5=imfilter(img,fspecial('log',5,0.5),'replicate','same');
I6=imfilter(img,fspecial('motion',20,30),'replicate','same');
I7=imfilter(img,fspecial('prewitt'),'replicate','same');
I8=imfilter(img,fspecial('sobel'),'replicate','same');

figure(1);
imshow(img);

figure(2);
subplot(241),imshow(I1);
title('mean filter');
subplot(242),imshow(I2);
title('Circular area mean filter');
subplot(243),imshow(I3);
title('Gaussian low-pass filter');
subplot(244),imshow(I4);
title('Laplacian');
subplot(245),imshow(I5);
title('Laplacian Gaussian operator');
subplot(246),imshow(I6);
title('Motion blur operator');
subplot(247),imshow(I7);
title('prewitt operator');
subplot(248),imshow(I8);
title('sobel operator');

Realization effect:
(1) Original image:

(2) Images processed through various filters

Related Posts

Complete interpretation of YOLOv5 network structure [source code + hand-drawn network structure + module structure]

2022 “Graduate Students’ Scientific Research Literacy Improvement” Series Public Welfare Lectures CNKI Research Test

Explain the profound in simple terms – understand DeepSORT (Principles) in one article with zero basic knowledge

“MATLAB Speech Signal Analysis and Synthesis (Second Edition)”: Chapter 5 Noisy Speech and Preprocessing

Configure and run ORBSLAM2 on Ubuntu20.04 (nanny-level tutorial)

CubeSLAM: Monocular 3D Object SLAM paper notes

MATLAB Basics – Basic Grammar

Nanny-level official yolov7’s training of own data sets and project deployment

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*