2017-09-01 85 views
2

我有一个图像,其中一些像素被有意地改为零。现在我想做一个双线性插值来找出使用邻域的新像素值,如双线性插值一样。但是,我不想调整图像大小(MATLAB只能使用调整大小功能进行双线性插值)。是否可以在MATLAB中使用插值而不调整图像大小?

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

+1

你可能会发现[inplant_nans](https://uk.mathworks.com/matlabcentral/fileexchange/4551-inpaint-nans)有用。而不是0使这些像素NaN,你应该能够使用该功能。 –

+0

非常感谢您的评论。但是,我正在实现一个图像处理方法,要求我使用双三次或双线性插值。您建议的代码是否执行这些插值技术? – mad

+1

不幸的是,我不认为它具有这些具体的方法,我只是用它自己很多的图像插值,它是相当不错的。如果你有这个特定的要求,你可能想看看别的地方。 –

回答

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

+0

在你的例子中,你有矩阵X,Y和Z,Z由X和Y组成。我只有一个有1500×1500×3维的矩阵Z.如何在我的例子中将矩阵X和Y中的Z矩阵分割? – mad

+0

'[X,Y] = meshgrid(1:1500,1:1500)'。请注意,X,Y是您评估Z的每个点的坐标。您可能想要独立插值第三维。 – m7913d

相关问题