如何在matlab中进行棋盘插值?

发布于 11-09 13:23 字数 510 浏览 5 评论 0原文

我有两个矩阵 AB ,其中包含形式为棋盘/棋盘式网格的值

AxAxAxAx...
xBxBxBxB...
AxAxAxAx...
xBxBxBxB...
...........
...........

,其中 x 表示我尚不知道的值想要(线性)插值。实现这一目标的最简单方法是什么?

首先可能是

C = zeros(size(A)+size(B));
C(1:2:end,1:2:end) = A;
C(2:2:end,2:2:end) = B;

获得上述矩阵。现在我可以遍历所有剩余点并取所有直接邻居的平均值,因为1)matlab中的for循环很慢,2)当然有一种方法可以使用< code>interp2,尽管这似乎需要类似 meshgrid 的网格。那么,这可以更容易/更快地完成吗?

I have two matrices A and B containing values for a checkerboard/chessboard-like grid of the form

AxAxAxAx...
xBxBxBxB...
AxAxAxAx...
xBxBxBxB...
...........
...........

Where x represents values not yet known which I want to (linearly) interpolate. What's the easiest way to achieve this?

First thing is probably

C = zeros(size(A)+size(B));
C(1:2:end,1:2:end) = A;
C(2:2:end,2:2:end) = B;

to obtain aforementioned matrix. Now I could loop through all remaining points and take the average of all direct neighbours, for 1) for loops in matlab are slow and 2) there's certainly a way to use interp2, though that seems to require a meshgrid-like grid. So, can this be done easier/faster?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

っ左2024-11-16 13:23:33

感谢 woodchips 的回答在这里我找到了他的inpaint_nans,解决办法确实很简单:

C = nan(size(A)+size(B));
C(1:2:end, 1:2:end) = A;
C(2:2:end, 2:2:end) = B;
C = inpaint_nans(C);

Thanks to woodchips' answer here I found his inpaint_nans, the solution is indeed simple:

C = nan(size(A)+size(B));
C(1:2:end, 1:2:end) = A;
C(2:2:end, 2:2:end) = B;
C = inpaint_nans(C);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文