How to calculate the orientation/angle of a 3D gradient.
7 views (last 30 days)
Show older comments
Hi,
For a project I need to calculate the average gradient angle of each 3x3x3 box in a volume. There are a lot answers to do this in 2D but I cannot find something to do this in a 3D volume.
Does somebody know if there is a possible solution for this?
4 Comments
Matt J
on 28 Nov 2014
I suppose the angle with (0,0,0).
(0,0,0) is 90 degrees to every vector, by convention...
I trying to reproduce the thin tissue detector as described by Schneider et al. [1]. In this alogrithm they calculate the average angle in a 3x3x3 neighbourhood in each voxel in a volume.
You'll need to tell us how they define that, so that we don't have to go read it ourselves.
Accepted Answer
Roger Stafford
on 28 Nov 2014
Edited: Roger Stafford
on 28 Nov 2014
I did in fact look at equation (1) of the article you referenced, R Bruggink. If that is the computation you are asking about, it is simply the mean (average) of the angles BETWEEN different gradient vectors at the various points of a 3D cube. (You presumably left out the crucial word 'between' in describing your problem.) Finding the angle between two vectors in three dimensions is a problem that has been asked about a great many times in these matlab forums. The authors of the above article use arccos which would be 'acos' in matlab, but in my opinion, a formula using 'atan2' is superior in accuracy though it requires a bit more computation.
If g1 and g2 are two 3D vectors - that is, 3-element arrays containing x,y,z components of the two vectors - the angle between them in radians is given by:
a12 = atan2(norm(cross(g1,g2)),dot(g1,g2));
Now let G be an N-by-3 matrix in which each row is one of the gradient vectors of a p x p x p cube with N = p^3. Then you could compute the desired average of all possible pairings in this cube by;
s = 0;
for ix = 1:N-1
for jx = i+1:N
s = s + atan2(norm(cross(G(ix,:),G(jx,:))),dot(G(ix,:),G(jx,:)));
end
end
s = s/(N*(N-1)/2); % Divide by the total number of pairings
The variable 's' will be the mean (average) angle in radians between gradient pairs.
More Answers (0)
See Also
Categories
Find more on 3-D Volumetric Image Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!