Vector components along another one
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Gianfranco
il 15 Lug 2014
Risposto: Roger Stafford
il 15 Lug 2014
this is my situation: I have a 30x30 image and I want to calculate the radial and tangent component of the gradient of each point (pixel) along the straight line passing through the centre of the image (15,15) and the same (i,j) point.
[dx, dy] = gradient(img);
for i=1:30
for j=1:30
pt = [dx(i, j), dy(i,j)];
line = [i-15, j-15];
costh = dot(line, pt)/(norm(line)*norm(pt));
par(i,j) = norm(costh*line);
tang(i,j) = norm(sin(acos(costh))*line);
end
end
is this code correct?
0 Commenti
Risposta accettata
Roger Stafford
il 15 Lug 2014
In the line
par(i,j) = norm(costh*line);
it should be
par(i,j) = costh*norm(line);
to allow the inward and outward radial components to be distinguished.
In the line
tang(i,j) = norm(sin(acos(costh))*line);
you will be unable to distinguish between clockwise and counterclockwise tangential components. To correct this you need to compute something other than the cosine of the angle between the two vectors. The sine of acos will always be positive. I would recommend this for both 'par' and 'tang':
line = line/norm(line);
tang(i,j) = line(1)*pt(2)-line(2)*pt(1);
par(i,j) = line(1)*pt(1)+line(2)*pt(2);
instead of computing 'costh'.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Point Cloud Processing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!