是否可以在不调整图像大小的情况下在MATLAB中使用插值?

时间:2017-09-01 08:56:04

标签: matlab image-processing interpolation

我有一张图片,其中有些像素故意改为零。现在我想进行双线性插值,以便像双线性插值那样使用邻域找出新的像素值。但是,我不想调整图像的大小(MATLAB只能通过调整大小功能进行双线性插值)。

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

1 个答案:

答案 0 :(得分:4)

您可以尝试使用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);

enter image description here enter image description here