Need help with implementing a 2D elliptical Gaussian function
45 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to implement a 2D gaussian function, which has an elliptical shape rather than circular. For example if I have a standard Gaussian fuction such as: f=a1*exp(-(((x-b1)/c1).^2+((y-b1)/c1).^2))
where [x,y]=meshgrid(xmin:spacing:xmax,ymin:spacing,yman); I can just f=a1*exp(-((r-b1)/c).^2) where r=sqrt(x^2+y^2);
however if my c1 is not the same, I will have an ellipse. I'm not sure how to implement this. Any help will be highly appreciated.
0 件のコメント
回答 (2 件)
David Young
2011 年 7 月 5 日
You can make an elliptical filter aligned with the axes by replacing the second occurrence of c1 by a different variable, say c2, and giving c1 and c2 different values. Here's some code that demonstrates what I mean; I've taken the opportunity to change b1 to b2 as well, so the centre of the filter can be moved to an arbitrary point:
% Set up mesh
xmin = -100;
xmax = 100;
ymin = -100;
ymax = 100;
spacing = 1;
xvals = xmin:spacing:xmax+spacing/2;
yvals = ymin:spacing:ymax+spacing/2;
[x,y] = meshgrid(xvals, yvals);
% parameters for the gaussian
a1 = 1;
b1 = 20;
b2 = 40;
c1 = 10;
c2 = 40;
% Compute the filter and display it
f=a1.*exp(-(((x-b1)./c1).^2+((y-b2)./c2).^2));
contour(x, y, f);
If you want the ellipse to be oriented in an arbitrary direction, you need to rotate the axes before the computation. This involves multiplying x and y by a rotation matrix. Please say if you also need help with this.
1 件のコメント
MJ HL
2017 年 8 月 22 日
Hello David, ... As you guessed I'm from that kind of people that need more help in rotating this filter :) . How should I do this? I need to rotate this filter in an arbitrary direction... thanks
参考
カテゴリ
Help Center および File Exchange で Digital and Analog Filters についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!