MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   将1D高斯插值到2D高斯 (https://www.labfans.com/bbs/showthread.php?t=23205)

poster 2019-12-10 20:30

将1D高斯插值到2D高斯
 
假设我有一个一维高斯函数。长度为600。

我想将其插值为大小为600 X 600的2D高斯。

这是我编写的代码(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]); 问题是我最后得到超调: [URL="https://i.stack.imgur.com/qu27J.png"][IMG]https://i.stack.imgur.com/qu27J.png[/IMG][/URL]

如何防止这种过冲?单调下降函数是否有更好的插值算法?

[B]注意:[/B]我正在寻找一种将一维函数内插到二维径向对称函数中的通用解决方案,高斯只是一个例子。



[B]回答:[/B]

编辑:根据您的澄清,很清楚发生了什么事。您正在尝试对可用数据范围以外的函数进行插值-即,您正在从插值过渡到外推。样条曲线将导致您观察到的过冲。解决方案只是确保您的一维函数的值在[min(r),max(r)]区间内。请注意,在原始数据中,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) [URL="http://img54.imageshack.us/img54/8255/clipboard01vz.png"]替代文字http://img54.imageshack.us/img54/8255/clipboard01vz.png[/URL]



[url=https://stackoverflow.com/questions/2443046]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 05:06

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.