0

I have a matrix with data of a topography, let's say several hills. I want to have information of the angle of each data point to the vertical line. Here are two examples:

  1. If I consider a place near the foot of the hill that is totally flat, I have a degree of 90° (90° to the vertical line).
  2. If I am at the steepest point of the hill, I have a lower angle of let's say 50°.

To compute this I guess I have to to connect all the topography data so that (at least) three near pixels form triangle. After that I have to compute the angle(s) of this triangle.

Can I use a existing algorithm?

tardis
  • 1,280
  • 3
  • 23
  • 48
  • can you add an example image? And also which angles exactly are you talking about? I suspect [`imgradient`](https://uk.mathworks.com/help/images/ref/imgradient.html) might be useful for you, but I do not understand the question very well. – Vahe Tshitoyan Jun 28 '17 at 14:38

1 Answers1

1

If your heightmap is a matrix A then you could approximate the the gradient components of every inner point (without the egdes) by

  Xgrad = (A(2:end-1,3:end)-A(2:end-1,1:end-2))/2;
  Ygrad = (A(3:end,2:end-1)-A(1:end-2,2:end-1))/2;

The angulars will then be

  deg = (pi/2 - atan(sqrt(Xgrad.^2 + Ygrad.^2),1))/pi*180;

Depending on your heightmap, differentiating numerically can produce "fuzzy" results. Maybe you have to do some blur-filtering in order to produce smoother gradients.

Loamsiada
  • 444
  • 3
  • 11