# Gradient calculation from a starting point in image

6 visualizzazioni (ultimi 30 giorni)
Adele Campus il 19 Mag 2023
Risposto: Kshittiz il 24 Mag 2023
hello everyone,
I'm trying to calculate a gradient from a matrix of double starting from a selected point. I have the coordinates (in terms of x and y) of this point and the values in my matrix represent the measures of the heights of a volcano (a sort of DEM). Form a starting point which corresponds to a specific height, I would find the pattern with the highest gradient in order to identify a sort of path that lava flows may travel.
My mental approach (I have problems also in developing this script) is to start a loop in which I should find, from my starting pixel P1, the pixel with lower height (Lpix) between the 8 around it, select the lowest-height pixel (Lpix) and then from Lpix start a new 'research' of the pixel with lowest height in the area of 8 pixel around it and find the Lpix2 and so on in order to define the already mentioned 'probable lava flow pattern' I need.
Are there any faster solutions or specific functions that can make this procedure easier?
Thank you!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Kshittiz il 24 Mag 2023
I understand that you are iteratively searching for the pixel with the lowest height in the neighbourhood and then working your way to find a path with the highest gradient.
Here are some alternate approaches that may be faster and more efficient:
Instead of searching for the lowest height pixel, calculate the gradient at each pixel using numerical differentiation. MATLAB's gradient functions (gradient or gradientm) can help identify the steepest ascent or descent direction, which can potentially indicate the likely path of lava flow.
Alternative Approach 2: Topographical Analysis
MATLAB has specialized functions like imgradient and imgradientmagfor analyzing topography. They compute gradients and magnitudes, assisting in identifying paths and flow directions and can be beneficial in analyzing your volcano's Digital Elevation Model (DEM).
Alternative Approach 3: Image Processing Toolbox
If available, the Image Processing Toolbox offers functions like bwlabel and imregionalmin for analyzing DEMs. They can help identify regions and local minima, providing insights into lowest points and connectivity..
Alternative Approach 4: Optimization Techniques
Formulate the problem as an optimization task, treating pixel heights as a cost function. Utilize optimization algorithms like gradient descent from MATLAB's Optimization Toolbox to search for paths with the highest gradient, potentially indicating lava flow paths.
Note that usage of any of the above alternative approaches depends on your particular use case and the speed can also vary according to that.
Thanks!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Image Segmentation and Analysis in Help Center e File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by