Defining an n x n matrix that is the Gaussian

39 views (last 30 days)
I am doing practice problems in a digital image processing book One of the questions is:
Define an 9x9 matrix that is a Gaussian function of the form exp(−((x−x0)^2+(y−y0)^2)/w)where x0 and y0 denote the center of the matrix and w is a width parameter.
x0 & y0 = 64
You are supposed to experiment with the values of w to see what happens I am extremely new to MATLAB
My thoughts were creating a 9x9 matrix of ones and multiplying it by the function???? However I am pretty sure a loop needs to be made.
I don't know how to input functions or how to go about this. Later it says to convolve this matrix with a previous matrix I made (which I do now how to do...lol)

Accepted Answer

Image Analyst
Image Analyst on 23 Sep 2014
You don't need a loop. You can use fspecial() if you have the Image Processing Toolbox. See my DOG filter demo, attached. If you want a loop, you can do (untested)
gFilter = zeros(9,9);
x0=64;
y0=64;
for col = 1 : 9
for row = 1 : 9
gFilter(row, column) = exp(((colx0)^2+(rowy0)^2)/w);
end
end
Of course with the filter centered at 5,5 and your Gaussian centered at 64,64, your 9x9 array will be just a distant patch on the far side of the hump.
  2 Comments
MLnoob5340
MLnoob5340 on 23 Sep 2014
Image Analyst, thank you very much! I have a question about syntax. You are defining col and row in the for statements are columns and rows designated by the colon? so you are defining a matrix by setting its parameters and referencing back to gFilter?
Image Analyst
Image Analyst on 23 Sep 2014
gFilter is the 9 by 9 array that is the Gaussian filter. First I initialize it to all zeros, then I scan it element by element and assign the correct value according to your formula (strange as it may be). row and col are just normal for loop iterators just like any other for loop you've ever seen in MATLAB.

Sign in to comment.

More Answers (0)

Categories

Find more on Image Preview and Device Configuration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!