用MATLAB进行稀疏矩阵插值 [英] Sparse Matrix Interpolation With MATLAB

查看:242
本文介绍了用MATLAB进行稀疏矩阵插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这样的矩阵

A = [1 2; 3 4];

我可以像这样用interp2对其进行插值

I can use interp2 to interpolate it like this

newA = interp2(A,2);

然后我得到一个5x5的插值矩阵.

and I get a 5x5 interpolated matrix.

但是如果我有一个像这样的矩阵怎么办?

But what if I have a matrix like this:

B = zeros(20);
B(3,2) = 5;
B(17,4) = 3;
B(16, 19) = 2.3;
B(5, 18) = 4.5;

我将如何对这个矩阵进行插值(或填补空白).我已经研究过interp2以及TriScatteredInterp,但这些都似乎无法完全满足我的需求.

How would I interpolate (or fill-in the blanks) this matrix. I've looked into interp2 as well as TriScatteredInterp but neither of these seem to fit my needs exactly.

推荐答案

一个好的解决方案是使用我的 inpaint_nans .只需提供不存在任何信息的NaN元素,然后使用inpaint_nans.它将对NaN元素进行插值,并将其填充以与数据点平滑一致.

A good solution is to use my inpaint_nans. Simply supply NaN elements where no information exists, then use inpaint_nans. It will interpolate for the NaN elements, filling them in to be smoothly consistent with the data points.

B = nan(20);
B(3,2) = 5;
B(17,4) = 3;
B(16, 19) = 2.3;
B(5, 18) = 4.5;
Bhat = inpaint_nans(B);

surf(B,'marker','o')
hold on
surf(Bhat)

对于那些对inpaint_nans是否可以处理更复杂的表面感兴趣的人,我曾经拍摄过一张数字化的莫奈画(在左侧看到,然后通过随机删除50%的像素来破坏它.最后,我应用inpaint_nans进行了观察如果我能很好地恢复图像,则右边的图像是已修复的图像.分辨率较低时,恢复的图像是不错的恢复.

For those interested in whether inpaint_nans can handle more complex surfaces, I once took a digitized Monet painting (seen on the left hand side, then corrupted it by deleting a random 50% of the pixels. Finally, I applied inpaint_nans to see if I could recover the image reasonably well. The right hand image is the inpainted one. While the resolution is low, the recovered image is a decent recovery.

作为另一个示例,请尝试以下操作:

As another example, try this:

[x,y] = meshgrid(0:.01:2);
z = sin(3*(x+y.^2)).*cos(2*x - 5*y);
surf(x,y,z)
view(-23,40)

现在,删除此数组中大约7/8个元素,将其替换为NaN.

Now, delete about 7/8 of the elements of this array, replacing them with NaNs.

k = randperm(numel(z));
zcorrupted = z;
zcorrupted(k(1:35000)) = NaN;

使用修复进行恢复. z轴具有不同的缩放比例,因为在边缘的+/- 1上下都存在微小的变化,但否则,后一个表面是一个很好的近似值.

Recover using inpainting. The z-axis has a different scaling because there are minor variations above and below +/-1 around the edges, but otherwise, the latter surface is a good approximation.

zhat = inpaint_nans(zcorrupted);
surf(x,y,zhat)
view(-23,40)

这篇关于用MATLAB进行稀疏矩阵插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆