开发者

How to perform a checkerboard-interpolation in matlab?

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?


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜