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
The result should be
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 CommentsShow comments
Problem Recent Solvers23