使用 circshift 在 matlab / octave 中对角移动 martix

using circshift to shift martix diagonally in matlab / octave

如何对角移动矩阵单元格?

我有一张带有水平线的图像,如下所示:

我使用代码片段对角移动单元格,如下所示

reshaped_output = imresize(repmat_rgb, [640, 480]); %reshape output
imwrite(reshaped_output,strcat('/tmp/img/','orig','.png')); %will create file without borders and use any resize in repmat

[row, col, dim] = size(reshaped_output);

diag_shift_rgb=zeros(row, col, dim); %preallocate array
for ii=1:col
  bb_r=circshift(reshaped_output(:,ii,1),ii-1);
  bb_g=circshift(reshaped_output(:,ii,2),ii-1);
  bb_b=circshift(reshaped_output(:,ii,3),ii-1);
  diag_shift_rgb(:,ii,1)=[bb_r]; %over write array
  diag_shift_rgb(:,ii,2)=[bb_g]; %over write array
  diag_shift_rgb(:,ii,3)=[bb_b]; %over write array
end

imwrite(diag_shift_rgb,strcat('/tmp/img/','diag','.png')); %will create file without borders and use any resize in repmat

我的对角线确实发生了偏移,但是颜色随着偏移一起消失了我做错了什么?

Ps: 我正在使用类似于 matlab

的 Octave 4.0

另一个数字示例

Input Example with numbers
1                     1                     1                     1
2                     2                     2                     2
3                     3                     3                     3
4                     4                     4                     4
5                     5                     5                     5
6                     6                     6                     6
7                     7                     7                     7


Output example with numbers of what I'm trying to get with the image
1                     7                     6                     5
2                     1                     7                     6
3                     2                     1                     7
4                     3                     2                     1
5                     4                     3                     2
6                     5                     4                     3
7                     6                     5                     4

diag_shift_rgbdouble 类型,但它应该是 uint8 类型才能正确保存:

diag_shift_rgb = zeros (row, col, dim, "uint8");