필터 지우기
필터 지우기

diagonal pixel differences of image matrix

조회 수: 1 (최근 30일)
mahesh chathuranga
mahesh chathuranga 2013년 9월 17일
is there any method to get the diagonal pixel differences(left right diagonal) of a image matrix.for example , i have to obtain [-8 -2 -4;4 2 -16;0 2 4] from [2 1 8 24;9 10 3 12;2 5 8 19;1 2 3 4]

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 9월 17일
편집: Andrei Bobrov 2013년 9월 17일
b = [2 1 8 24;9 10 3 12;2 5 8 19;1 2 3 4];
out = rot90(spdiags(tril(triu(flipud(diff(flipud(spdiags(b,-2:2))))),2)));
other variant without spdiags
s = size(b);
c = ones(s + [0 s(1)-1]);
c1 = rot90(tril(triu(c),s(2)-1));
c1(c1>0) = b';
c2 = diff(c1');
c3 = c2(:,end-1:-1:2);
t = tril(triu(ones(size(c3))),s(2)-2);
c3 = rot90(c3);
out = zeros(s-1)';
out(:) = c3(rot90(t)>0);
out = -out';

추가 답변 (1개)

Teja Muppirala
Teja Muppirala 2013년 9월 17일
b = [2 1 8 24;9 10 3 12;2 5 8 19;1 2 3 4];
conv2(b,[-1 0; 0 1],'valid')
  댓글 수: 2
Andrei Bobrov
Andrei Bobrov 2013년 9월 17일
Hi Teja! +1. I again forgotten about conv.
Teja Muppirala
Teja Muppirala 2013년 9월 17일
Hello Andrei! conv is simpler, but your solution is definitely more creative and interesting.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by