【问题标题】:Expanding a 2D Matrix in Matlab with Interpolation在 Matlab 中使用插值扩展二维矩阵
【发布时间】:2018-02-24 06:03:59
【问题描述】:

假设我有一个 4 x 4 像素的图像,其值在 0 到 255 之间,我想将其扩展为 8 x 8 图像,并在必要时进行插值。我知道如何用 interp1 以这种方式插入 vector

interp1(linspace(0,1,numel(vector)), vector, linspace(0,1,newSize))

但我不清楚如何使用 interp2 为 matrix 做同样的事情。

编辑:如果我在为每个维度使用 linspace 之后创建一个网格网格,会不会一样?

EDIT2:是的,这有效。相同,但使用了网格。

【问题讨论】:

    标签: matlab interpolation linear-interpolation


    【解决方案1】:

    对于以规则网格形式结构化的数据,您可以使用interp2,正如您正确说明的那样,但是由于您正在处理图像,我建议您使用imresize function,它针对以下情况进行了微调使用适当的插值算法重新缩放图像:

    % Load an image and display it...
    img = imread('peppers.png');
    figure(),imshow(img);
    
    % Create a second image that is
    % twice the size of the original
    % one and display it...
    img2 = imresize(img,2);
    figure(),imshow(img2);
    

    无论如何,如果您真的想使用上述功能,我将执行以下插值:

    % Load an image, convert it into double format
    % and retrieve its basic properties...
    img = imread('rice.png');
    img = im2double(img);
    [h,w] = size(img);
    
    % Perform the interpolation...
    x = linspace(1,w,w*2);
    y = linspace(1,h,h*2);
    [Xq,Yq] = meshgrid(x,y);
    img2 = interp2(img,Xq,Yq,'cubic') ./ 255;
    
    % Display the original image...
    figure(),imshow(img);
    
    %Display the rescaled image...
    figure(),imshow(img2,[]);
    

    【讨论】:

      猜你喜欢
      • 2014-07-19
      • 2012-06-07
      • 1970-01-01
      • 2014-09-06
      • 1970-01-01
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 2015-01-10
      相关资源
      最近更新 更多