Hello,

I am looking to create a hillshade function, but issues arise defining the the 
X and Y gradients.

The test code so far:

function [grad_x, grad_y] = compute_gradients(dem)
    grad_x = diff(dem, 1, 'c');
    grad_y = diff(dem, 1, 'r');
endfunction

// Create a test DEM grid
dem=[1.23  1.45  1.67  1.89  2.10;...
    1.54  1.73  1.92  2.11  2.30;...
    1.85  2.01  2.17  2.33  2.49;...
    2.16  2.29  2.42  2.55  2.68];

// Compute gradient
[grad_x, grad_y] = compute_gradients(dem);

// Display the results
disp('Gradient in x-direction:');
disp(grad_x);

disp('Gradient in y-direction:');
disp(grad_y);

function slope = compute_slope(grad_x, grad_y)

    // Compute magnitude of gradient vector
    magnitude = sqrt(grad_x.^2 + grad_y.^2);

    // Compute slope using arctangent
    slope = atan(magnitude);
endfunction

slope = compute_slope(grad_x, grad_y);
disp(slope)

How to make the grad_x and grad_y matrices the same size?
One route may be central differences as a method:

function [grad_x, grad_y] = calculate_gradient(Z)
    [m, n] = size(Z);
    grad_x = zeros(m, n);
    grad_y = zeros(m, n);

    for i = 2:(m-1)
        for j = 2:(n-1)
            grad_x(i, j) = (Z(i+1, j) - Z(i-1, j)) / 2;
            grad_y(i, j) = (Z(i, j+1) - Z(i, j-1)) / 2;
        end
    end
endfunction

Any suggestions how to gradients for grid data.

Thanks
Lester


This email and any attachments are intended solely for the use of the 
individual or entity to whom it is addressed and may be confidential and/or 
privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email 
and all attachments,

(iii) Dassault Systèmes does not accept or assume any liability or 
responsibility for any use of or reliance on this email.


Please be informed that your personal data are processed according to our data 
privacy policy as described on our website. Should you have any questions 
related to personal data protection, please contact 3DS Data Protection Officer 
https://www.3ds.com/privacy-policy/contact/

_______________________________________________
users mailing list - users@lists.scilab.org
Click here to unsubscribe: <mailto:users-unsubscr...@lists.scilab.org>
https://lists.scilab.org/mailman/listinfo/users

Reply via email to