Problem 852. Index of neighbor pixel with steepest gradient
Unlike in various applications, where the gradient of a two dimensional matrix is calculated in x and y direction, the gradient of a digital elevation model (DEM) is usually returned as the steepest gradient. The steepest gradient is the largest downward slope of a pixel to one of its eight neighbors.
In this problem, your task will be to return the linear index of the steepest neighbor for each pixel in a gridded DEM. Pixels that don't have downward neighbors should receive the index value zero.
An example should help. The DEM is
dem = [1 5 9; ...
4 5 6; ...
8 7 3];
The result should be
IX = [0 1 4; ...
1 1 9; ...
2 9 0];
The results may not be unique, but the test cases have been built so that this is not a problem. The spatial resolution of the dem is dx=1 and dy=1. Note that the diagonal distance is hypot(dx,dy).
Solution Stats
Problem Comments
-
5 Comments
Show
2 older comments
Dishant Arora
on 2 Aug 2012
I'v developed the code using padarray and ordfilt2, which satisfies the test suite on my system, but seems like cody doesn't support padarray, is this so??
Wolfgang Schwanghart
on 2 Aug 2012
Hi Dishant, I thought the IPT is available, too, but apparently Cody does not support toolboxes at this time. see box on the right hand side: http://www.mathworks.de/matlabcentral/about/cody/
Jean-Marie Sainthillier
on 19 Aug 2014
More difficult thant expected...
Rafael S.T. Vieira
on 8 Jun 2020
Pay attention. The problem is asking for the index and not the value of the steepest gradient. And gradients on diagonals directions must be divided by sqrt(2).
Dyuman Joshi
on 22 Dec 2022
Test cases have been added and solutions have been rescored.
Solution Comments
Show comments
Problem Recent Solvers23
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!