将matlab上的m*n图像矩阵右移

Shift m*n image matrix on matlab to the right

我目前有一个 m*n 的灰度点图像矩阵。我想将图像向右移动一定数量的像素。下面的代码似乎将它向右和向上移动。我怎样才能解决这个问题?我需要进行某种矩阵运算来进行移位,因此内置函数将无法工作。

% Performs a shift on an input image matrix
function shift(CBout, matrix)    
    [m,n]=size(CBout);
    T=ones(m,n)*200;

    CBout = T+CBout;

    plot(CBout(1,:), CBout(2,:), 'k.');
    scale = 400;
    axis([-scale scale -scale scale])
end

我想通了。我只是创建一个 ones 向量,然后将其添加到 mxn 矩阵的第一行。

% Performs a shift on an input image matrix
function shift(CBout, amount)
    disp('Shifting...');

    n = size(CBout, 2);
    T=ones(1,n)*amount;

    % Add shift amount to every element in the first row
    CBout = [CBout(1,:)+T; CBout(2,:)];

    plot(CBout(1,:), CBout(2,:), 'k.');
    scale = 400;
    axis([-scale scale -scale scale])
end