桃花猪 发表于 2007-7-30 19:27

高斯平均算子检测物体

%Template for Gaussian averaging
%Usage =Gaussian_templete(number,number)
%winsize-size of template(odd,integer)
%sigma-variance of Gaussian function
f=imread(Ɖ.JPG');
winsize = zeros(5,5);
sigmasize=;
f1=rgb2gray(f);
=size(f1);
=size(winsize);
=size(sigmasize);
% centre is half of window size
%centre=floor(winsize/2)+1
crhalf=floor(wrows/2)+1;
cchalf=floor(wcols/2)+1;
%we will normalise by the total sum
sum=0;
%so work out the coefficients and the rumming total
for j=1:wrows
      for i=1:wcols
          f2(j,i)=exp(-(((j-cchalf)*(j-cchalf))+((i-crhalf))*((i-crhalf)))/(2*srows*scols));%f2:template
          sum=sum+f2(j,i);
      end
end
%and then normlise
f2(j,i)=f2(j,i)/sum;
imshow(f2,);



修改之后程序没有错误,可是出来的图超级小,针尖小,为什么呢?肯定是程序有问题。


如果我加入f2=zeros(irows,icols);显示的图像大小正常,但是是全部黑色。
%Template for Gaussian averaging
%Usage =Gaussian_templete(number,number)
%winsize-size of template(odd,integer)
%sigma-variance of Gaussian function
f=imread('a.JPG');
winsize = zeros(5,5);
sigmasize=zeros(1,1);
f1=rgb2gray(f);
=size(f1);
=size(winsize);
=size(sigmasize);
f2=zeros(irows,icols);
% centre is half of window size
%centre=floor(winsize/2)+1
crhalf=floor(wrows/2)+1;
cchalf=floor(wcols/2)+1;
%we will normalise by the total sum
sum=0;
%so work out the coefficients and the rumming total
for j=1:wrows
      for i=1:wcols
          f2(j,i)=exp(-(((j-cchalf)*(j-cchalf))+((i-crhalf))*((i-crhalf)))/(2*srows*scols));%f2:template
          sum=sum+f2(j,i);
      end
end
%and then normlise
f2(j,i)=f2(j,i)/sum;
imshow(f2,);

风花雪月 发表于 2007-9-3 09:37

很显然,你这里设置
winsize = zeros(5,5);
换句话来说
wrows,wcols两个值都是5,因此你行成的f2就只能是5*5的

你加上f2=zeros(irows,icols);后
虽然f2的大小和f1一致了,但是实际上的数据操作还是仅限于5*5的范围内
而其它点的值都是0,显然是黑色的
页: [1]
查看完整版本: 高斯平均算子检测物体