Side note: First draft on Mar 18 2011. Everything popular tends to become a verb. “Let’s Google it.”, “Did you tweet today?”… Well, Gaussian deserves to be a verb also.

1. 1-D Gaussian Filter

1-D Gaussian filter can be created according to the normal distribution function below,


The sample matlab code is given below,


A plot of the GUASS will give you the graph below,


2. 2-D Gaussian Filter

2-D Gaussian Filter can be created based on the following formula,


The sample matlab code is given below,


The surfc function gives the plot below,


2. fspeical and imfilter: 2-D Gaussian Filter

fspecial is used to create several kinds of predefined 2-D filter in matlab, including “gaussian”. imfilter can be used to apply the created filter to multidimensional images.

fspecial takes three input parameters, with the syntax h = fspecial(‘gaussian’, hsize, sigma). hsize can be a vector specifying the number of rows and cols in the generated filter h, or a scalar indicating equal size for height and width. Sigma is the standard deviation marking the thiness of the gaussian.

imfilter takes at least two input parameters, with the syntax B = imfilter(A, H, …), where A is the input matrix, H is the filter. The common options include following,

  • Output Size Options:
    1. ‘same’: output is the same size as input. Default behavior if not specified
    2. ‘full’: output is full filtered result, which is larger than input.
  • Correlation and Convolution Options:
    1. ‘corr’: use correlation operations for filtering. Default behavior if not specified.
    2. ‘conv’: use convolution operations for filtering.

This predefined Gaussian filter use the formula below to create the filter,


Sample matlab code is given as below,


The surfc(h) gives the following plot,






One Response to How to Gaussian in Matlab

  1. adnane says:

    please how to plot this gaussian function on matlab

Leave a Reply

Your email address will not be published.

* Copy This Password *

* Type Or Paste Password Here *

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>

Set your Twitter account name in your settings to use the TwitterBar Section.