Vector components along another one
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Roger Stafford
2014-7-15
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Point Cloud Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!