matlab练习程序(生成高斯图像)

cl;
m=31;
n=31;
img=zeros(m+1,n+1);
img=double(img);
pi=3.1415926;
sigma=10;
for i=-(m/2):m/2
for j=-(n/2):n/2
img(i+m/2+1,j+n/2+1)=(1/(2*pi*sigma*sigma))*exp(-(i*i+j*j)/(2*sigma*sigma));
end
end
img=mat2gray(img);
imshow(img);
imwrite(img,'pic.bmp');

%一个更好的实现,2012.12.18修改

h=5;
w=2;
[x y]=meshgrid(-w:w,-h:h);
sigma=5;
img = (1/(2*pi*sigma^2))*exp(-(x.^2+y.^2)/(2*sigma^2));

posted @ 2012-02-26 12:53  Dsp Tian  阅读(8845)  评论(3编辑  收藏  举报