简体   繁体   English

将1D高斯内插到2D高斯分布

[英]Interpolating 1D Gaussian into 2D Gaussian

Let's say I have a 1D Gaussian function. 假设我有一维高斯函数。 Its length is 600. 它的长度是600。

I want to interpolate it into a 2D Gaussian of the size 600 X 600. 我想将其插值为600 X 600的2D高斯。

This is the code I wrote (OTFx is the Gaussian Function, OTF - 2d Interpolated Function): 这是我写的代码(OTFx是高斯函数,OTF - 2d插值函数):

[x, y] = meshgrid([-300:299], [-300:299]);
r = sqrt((x .^ 2) + (y .^ 2));

OTF = interp1([-300:299], OTFx, r(:), 'spline');
OTF = reshape(OTF, [600, 600]);

The problem is I get Overshoot at the end: 问题是我最后得到了Overshoot: 替代文字

How can I prevent this overshoot? 如何防止这种过冲? Is there better interpolating algorithm for monotonic descending functions? 是否有更好的单调递减函数插值算法?

NOTE: I am looking for a generic solution for interpolating a 1D function into a 2D radially symmetric function, the Gaussian is just an example. 注意:我正在寻找一种将1D函数插值为2D径向对称函数的通用解决方案,高斯只是一个例子。

EDIT: based on your clarification, it's clear what's going on. 编辑:根据您的澄清,很明显发生了什么。 You are trying to interpolate a function beyond the range of available data -- ie you are going from interpolation to extrapolation. 您正在尝试插入超出可用数据范围的函数 - 即您将从插值到外推。 Splines are going to result in the overshoot that you are observing. 样条曲线将导致您观察到的过冲。 The solution is simply to make sure that your 1D function has values in the interval [min(r), max(r)]. 解决方案只是确保您的1D函数在区间[min(r),max(r)]中具有值。 Note that in the original data, max(r) is about 424, while the function you are interpolating is defined on the range [-300,299] 请注意,在原始数据中,max(r)约为424,而要插值的函数在[-300,299]范围内定义

% Simulated overshoot, see left figure:
x1d = [-300:299];
[x,y]=meshgrid(x1d,x1d);
r = sqrt(x.^2+y.^2);
gsn1d = exp(-x1d.^2/500);
lowpass = @(x)(x1d > -x & x1d < x);
gsn1dcutoff = ifft(fftshift(lowpass(10).*fftshift(fft(gsn1d))));
plot(gsn1dcutoff)
OTF2d = reshape(interp1(x1d,gsn1dcutoff,r(:),'spline'),[length(x1d),length(x1d)]);
mesh(OTF2d)

% Quick and dirty fix, see right figure:
x1dExtended = linspace(min(x1d*sqrt(2)),max(x1d*sqrt(2)),ceil(length(x1d)*sqrt(2)));
gsn1dE = exp(-x1dExtended.^2/500);
% ^^^ note that this has 600*sqrt(2) points and is defined on the diagonal of your square.   Now we can low-pass filter in the freq. domain to add ripple in space domain:
lowpass = @(x)(x1dExtended > -x & x1dExtended < x);
gsn1dcutoff = -real(ifft(fftshift(lowpass(10).*fftshift(fft(gsn1dE)))));
plot(gsn1dcutoff)
OTF2d = reshape(interp1(x1dExtended,gsn1dcutoff,r(:),'spline'),[length(x1d),length(x1d)]);
mesh(OTF2d)

alt text http://img54.imageshack.us/img54/8255/clipboard01vz.png 替代文字http://img54.imageshack.us/img54/8255/clipboard01vz.png

Leo is right in his diagnosis. Leo的诊断是正确的。 I'd like to suggest a simpler (I hope) remedy: to do what you want to do (which is basically rotate a Gaussian around its symmetry axis) and to get a reasonable answer in a 600x600 square you need a Gaussian 600*sqrt(2)=849 pixels long. 我想建议一个更简单的(我希望)补救措施:做你想做的事情(基本上围绕其对称轴旋转高斯)并在600x600方格中得到合理的答案你需要一个高斯600 * sqrt (2)= 849像素长。 If you can do that, then all further thttp://stackoverflow.com/questions/2443046/interpolating-1d-gaussian-into-2d-gaussianrickery is not necessary. 如果你能做到这一点,那么所有进一步的thttp://stackoverflow.com/questions/2443046/interpolating-1d-gaussian-into-2d-gaussianrickery都不是必需的。

Edit : In other words: if you rotate something 600 pixels wide around its center, you get a circle 600 pixels in diameter. 编辑 :换句话说:如果围绕其中心旋转600像素宽的内容,则会得到直径为600像素的圆。 You want to cover a 600x600 square . 你想要覆盖600x600 平方 For that you need a circle 849 pixels in diameter, since this is the diagonal of the square. 为此你需要一个直径为849像素的圆,因为这是正方形的对角线。

In the particular case of the gaussian, you may compute the gaussian by using the fact that it is separable: 在高斯的特定情况下,您可以通过使用它可分离的事实来计算高斯:

OTF2(x,y) = exp( - x^2 - y^2) = exp( - x^2) * exp( - y^2) = OTFx(x) * OTFx(y)

So you still just need to store just OTFx in memory. 所以你仍然只需要将OTFx存储在内存中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM