How to make a Gaussian filter in Matlab

后端 未结 2 1203
轮回少年
轮回少年 2020-12-03 15:50

I have tried to make a Gaussian filter in Matlab without using imfilter() and fspecial(). I have tried this but result is not like the one I have w

2条回答
  •  长情又很酷
    2020-12-03 16:37

    here's an alternative:

    Create the 2D-Gaussian:

      function f=gaussian2d(N,sigma)
      % N is grid size, sigma speaks for itself
     [x y]=meshgrid(round(-N/2):round(N/2), round(-N/2):round(N/2));
     f=exp(-x.^2/(2*sigma^2)-y.^2/(2*sigma^2));
     f=f./sum(f(:));
    

    Filtered image, given your image is called Im:

     filtered_signal=conv2(Im,gaussian2d(N,sig),'same');
    

    Here's some plots:

    imagesc(gaussian2d(7,2.5))
    

    enter image description here

     Im=rand(100);subplot(1,2,1);imagesc(Im)
     subplot(1,2,2);imagesc(conv2(Im,gaussian2d(7,2.5),'same'));
    

    enter image description here

提交回复
热议问题