I have written a logic for co-occurance matrix but it is taking a lot of time, is there any other to built the logic?

조회 수: 1 (최근 30일)
4.Calculate four co-occurrence matrices P, take the distance 1, the angles are 0, 45, 90, 135 respectively
%M&N ARE ROWS &COLOUMNS OF THE IMAGE
%--------------------------------------------------------------------------
P = zeros(16,16,4); %Generate 4 16 * 16 0 matrix
for m = 1:16
for n = 1:16
for i = 1:M
for j = 1:N
if
j<N&Gray(i,j)==m-1&Gray(i,j+1)==n-1 %0 ° m for the row n for the column
P(m,n,1) = P(m,n,1)+1;
P(n,m,1) = P(m,n,1);
end
if i>1&j<N&Gray(i,j)==m-1&Gray(i-1,j+1)==n-1 %45°
P(m,n,2) = P(m,n,2)+1;
P(n,m,2) = P(m,n,2);
end
if i<M&Gray(i,j)==m-1&Gray(i+1,j)==n-1 %90°
P(m,n,3) = P(m,n,3)+1;
P(n,m,3) = P(m,n,3);
end
if i<M&j<N&Gray(i,j)==m-1&Gray(i+1,j+1)==n-1 %135°
P(m,n,4) = P(m,n,4)+1;
P(n,m,4) = P(m,n,4);
end
end
end
if m==n
P(m,n,:) = P(m,n,:)*2;
end
end
end

답변 (3개)

Walter Roberson
Walter Roberson 2018년 2월 6일
You could vectorize. Or you could use graycomatrix()
  댓글 수: 6
Walter Roberson
Walter Roberson 2018년 2월 14일
Under the conditions that all values in Gray are integers in the range 0 to 15, then your code
for m = 1:16
for n = 1:16
for i = 1:M
for j = 1:N
j<N&Gray(i,j)==m-1&Gray(i,j+1)==n-1 %0 ° m for the row n for the column
P(m,n,1) = P(m,n,1)+1;
P(n,m,1) = P(m,n,1);
end
end
end
end
can be replaced by
V = @(M) M(:);
P0 = accumarray(1+[V(Gray(:,1:end-1)), V(Gray(:,2:end))], 1);
This will make P0 a 16 x 16 matrix containing the applicable counts.
Your other three conditions can be created with similar lines. You can then put all four of them together into your P matrix.
P = cat(3, P0, P45, P90, P135);

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


Roger Stafford
Roger Stafford 2018년 2월 14일
편집: Roger Stafford 2018년 2월 15일
In the code you have written the tests are false the great majority of the cases, and that suggests strongly that the method can be made more efficient.
Since you mention “image” in connection with rows and columns of ‘Grey’, I will assume all the values in ‘Grey’ are non-negative integers. I will add 1 to the values of ‘Grey’ and replace any that then exceed 17 by 17 itself. This latter will make P have just one extra row and one extra column of false values which will be discarded at the end.
P = zeros(17,17,4);
G = reshape(min(Grey(:)+1,17),size(Grey));
for i = 1:M
for j = 1:N-1
m = G(i,j);
n = G(i,j+1);
P(m,n,1) = P(m,n,1)+1;
end
end
for i = 2:M
for j = 1:N-1
m = G(i,j);
n = G(i-1,j+1);
P(m,n,2) = P(m,n,2)+1;
end
end
for i = 1:M-1
for j = 1:N
m = G(i,j);
n = G(i+1,j);
P(m,n,3) = P(m,n,3)+1;
end
end
for i = 1:M-1
for j = 1:N-1
m = G(i,j);
n = G(i+1,j+1);
P(m,n,4) = P(m,n,4)+1;
end
end
P = P(1:16,1:16,:); % Trim off one row and one column
P = P + permute(P,[2,1,3]); % Replaces the "P(n,m,-)=P(m,n,-)" above
  댓글 수: 6

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


teja jayavarapu
teja jayavarapu 2018년 2월 15일
편집: teja jayavarapu 2018년 2월 15일
Ok,thank you for the support,can you please help me with the Gussian internal normalisation for texture parameters of (capacity,entropy,relevance,inverse difference)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by