缩小某些条目未知的矩阵

时间:2012-09-27 18:02:10

标签: image matlab image-processing signal-processing

我有一个2D网格(G = 250x250),其中只有大约100个点是已知的,其余的是未知的(NaN)。我想调整这个矩阵的大小。我的问题是imresize无法在MATLAB中为我做这件事,因为它为我删除了已知值并且只给出了一个NaN矩阵。

任何人都知道一种可以为我做的方法吗?建议使用插值方法(例如使用反距离加权),但我不确定它是否有效,甚至是否有更好的方法?

    G = NaN(250,250);
    a = ceil(rand(1,50)*250*250);
    b = ceil(rand(1,50)*250*250);
    G (a) = 1; G (b) = 0;

1 个答案:

答案 0 :(得分:2)

这个怎么样:

% find the non-NaN entries in G
idx = ~isnan(G);

% find their corresponding row/column indices
[i,j] = find(idx);

% resize your matrix as desired, i.e. scale the row/column indices
i = ceil(i*100/250);
j = ceil(j*100/250);

% write the old non-NaN entries to Gnew using accumarray
% you have to set the correct size of Gnew explicitly
% maximum value is chosen if many entries share the same scaled i/j indices
% NaNs are used as the fill
Gnew = accumarray([i, j], G(idx), [100 100], @max, NaN);

如果max不适合你,你也可以为accumarray选择不同的累积函数。如果不是您需要的话,您可以将NaN的填充值更改为其他值。

相关问题