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

时间:2017-03-15 01:33:46

标签: image matlab matrix octave diagonal

如何对角移动矩阵细胞?

我的图像带有水平线,如下所示: Original horizontal lines Image

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

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

我确实得到了偏移的对角线,但颜色随着移动一起关闭我做错了什么?

Diagonal image

Ps:我使用Octave 4.0,类似于matlab

另一个带数字的例子

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

1 个答案:

答案 0 :(得分:1)

diag_shift_rgb属于double类型,但其类型uint8应正确保存:

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