【问题标题】:Is it possible to use interpolation in MATLAB without resizing an image?是否可以在不调整图像大小的情况下在 MATLAB 中使用插值?
【发布时间】:2017-09-02 03:51:16
【问题描述】:

我有一个图像,其中一些像素被故意更改为零。现在我想进行双线性插值,以使用邻域来找出新的像素值,就像双线性插值一样。但是,我不想调整图像大小(MATLAB 只能使用 resize 函数进行双线性插值)。

是否可以在不调整大小的情况下在 MATLAB 中进行双线性插值?我读到与双线性核的卷积可以解决这个问题。你知道这是哪个内核吗?有可能做我想做的事吗?

【问题讨论】:

  • 您可能会发现inplant_nans 很有用。这些像素不是 0,而是 NaN,您应该可以使用该函数。
  • 不幸的是,我认为它没有那些特定的方法,我自己只是经常使用它来进行图像插值,它非常好。如果你有这个特定的要求,你可能想看看其他地方。
  • 请看这个相关的answer。总之,可以使用inplant_nans(methods overview)或者TriScatteredInterp/scatteredInterpolant,都支持线性插值,不支持三次。
  • “不调整大小”是什么意思?如果您不创建新值,您想插入什么?这需要多一点解释。 interp2 进行各种类型的插值
  • @AnderBiguri 他们想用通过插值他们的邻居找到的值替换 0 值。

标签: matlab image-processing interpolation


【解决方案1】:

您可以尝试使用griddata支持的选项之一:

griddata(..., METHOD) where METHOD is one of
    'nearest'   - Nearest neighbor interpolation
    'linear'    - Linear interpolation (default)
    'natural'   - Natural neighbor interpolation
    'cubic'     - Cubic interpolation (2D only)
    'v4'        - MATLAB 4 griddata method (2D only)
defines the interpolation method. The 'nearest' and 'linear' methods 
have discontinuities in the zero-th and first derivatives respectively, 
while the 'cubic' and 'v4' methods produce smooth surfaces.  All the 
methods except 'v4' are based on a Delaunay triangulation of the data.

示例

% create sample data
[X, Y] = meshgrid(1:10, 1:10);
Z_original = X.*Y;

% remove a data point
Z_distorted = Z_original;
Z_distorted(5, 5) = nan;

% reconstruct
valid = ~isnan(Z_distorted);
Z_reconstructed = Z_distorted;
Z_reconstructed(~valid) = griddata(X(valid),Y(valid),Z_distorted(valid),X(~valid),Y(~valid));

% plot the result
figure
surface(Z_original);

figure
surface(Z_distorted);

figure
surface(Z_reconstructed);

【讨论】:

  • 在您的示例中,您有矩阵 X、Y 和 Z,Z 由 X 和 Y 组成。我只有一个矩阵 Z,尺寸为 1500x1500x3。如您的示例所示,如何将 Z 矩阵拆分为矩阵 X 和 Y?
  • [X, Y] = meshgrid(1:1500, 1:1500)。请注意,X、Y 是您评估 Z 的每个点的坐标。您可能希望独立插值第三个维度。
猜你喜欢
  • 1970-01-01
  • 2014-10-29
  • 1970-01-01
  • 1970-01-01
  • 2013-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多