【发布时间】:2017-08-05 14:16:58
【问题描述】:
如何对角移动矩阵单元格?
我使用代码的 sn-p 对角移动单元格,如下所示
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:我使用的是 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
【问题讨论】:
-
你的预期输出是什么?
-
@rahnema1 颜色在应该匹配的时候并不紧密匹配,如果你看一看,输出中的白色似乎比输入中的要多。这些线应该是对角线,这是正确的,输出数组大小也应该与原始数组大小相同。
-
@rahnema1 我添加了另一个数字示例。注意对角线倾斜(看 1 和 2)我正在尝试对颜色线做同样的事情
标签: image matlab matrix octave diagonal