【Matlab】图像插值函数interp2理解

来源:互联网 发布:怎么制作一个软件 编辑:程序博客网 时间:2024/05/19 03:45

图像插值就是利用已知邻近像素点的灰度值(或rgb图像中的三色值)来产生未知像素点的灰度值,以便由原始图像再生出具有更高分辨率的图像。

通过例子来理解interp2函数:

[X,Y] = meshgrid(-3:3); %产生网格坐标V = peaks(X,Y);         %通过网格坐标计算函数值,产生三维凹凸面figuresurf(X,Y,V)title('Original Sampling');%原始面
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

原始面

进行插值

[Xq,Yq] = meshgrid(-3:0.25:3);  %产生插值所需要的网格Vq = interp2(X,Y,V,Xq,Yq);      %通过对V线性插值(默认的)得到新的面Vqfiguresurf(Xq,Yq,Vq);title('Linear Interpolation Using Finer Grid');
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

插值结果

使用格式: 
Vq = interp2(X,Y,V,Xq,Yq) 
Vq = interp2(V,Xq,Yq) 
Vq = interp2(V) 
Vq = interp2(V,k) 
Vq = interp2(_,method) 
Vq = interp2(_,method,extrapval)

输入:

  • X,Y — Sample grid points 
    matrices | vectors

  • V — Sample values 
    matrix

  • Xq,Yq — Query points 
    scalars | vectors | matrices | arrays
  • k — Refinement factor 
    1 (default) | real, nonnegative, integer scalar
  • method — Interpolation method 
    ‘linear’ (default) | ‘nearest’ | ‘cubic’ | ‘spline’
  • extrapval — Function value outside domain of X and Y 
    scalar

输出:

  • Vq — Interpolated values 
    scalar | vector | matrix

原创粉丝点击