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)

Community Treasure Hunt

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

Start Hunting!

Translated by