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:
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


‘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.


‘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.


‘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.


‘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.


‘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.


‘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.


‘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');


title('mean filter');
title('Circular area mean filter');
title('Gaussian low-pass filter');
title('Laplacian Gaussian operator');
title('Motion blur operator');
title('prewitt operator');
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>