File Exchange

version 1.0.0.0 (1.51 KB) by
calculates a hillshade for a DEM (matrix)

Updated 07 May 2007

Function to calculate hillshade for a digital elevation model. Derives slope and aspect in radias to calculate shading value between 0 and 255 using a given lighting angle and altitude.

Altitude (angle above ground) and angle (direction/aspect) of lightsource can be given via args.

Derived using ESRIs hillshade algorithm, but uses simple GRADIENT function instead of Horns algorithm for slope calculation - factor 30 more efficient & no need for IP TB. (Thanks to Andrew Stevens)

Pls leave you feedback/rate.

### Cite As

Evana Rosylee

hi,

i was refering to your code on finding the slope and aspect up til the gradient part.it really is good and it helps me alot.now,i have a DEM image of 1400x1400 in bitmap format,grayscale(0-255).I need to pick two points on the pixel in order for me to calculate the slope and aspect.my problem now is,how can i automatically run for every pixel in the image?i know i have to use the loop function but i don't know how.any suggestion is welcome..thank u~

Giuliano Langella

I find very useful this function. I wonder if you have implemented also other hydrological/geomorphological functions in MatLab, such as PLAN/PROFILE curvatures, etc.

I suggest the following call to hillshade function in case of R reference matrix:
>> h = hillshade(Z, (R(3,1)+R(2,1)):R(2,1):(R(3,1)+size(Z,2)*R(2,1)), R(3,2)+R(1,2):R(1,2):(R(3,2)+size(Z,2)*R(1,2)));

with
R = [0,-cellsize; cellsize,0; up_left_pixel_X,up_left_pixel_Y];

Thanks.

Felix Hebeler

Implemented the GRADIENT function - thanks for the suggestions and code, its much faster now...

Andrew Stevens

Well done! Easy to use, good comments and produced a nice result for me. Thanks.

One question: could something like the "gradient" function be used instead of nlfilt. That way, users wouldn't need the IP toolbox to implement.

##### MATLAB Release Compatibility
Created with R2006b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux