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?

采纳的回答

Roger Stafford
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 个)

类别

Help CenterFile Exchange 中查找有关 Point Cloud Processing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by