Calculate the length of an object in image
13 views (last 30 days)
Show older comments
Adele Campus
on 17 May 2023
Commented: Antoni Garcia-Herreros
on 18 May 2023
Hi everyone,
I need some help in calculating the length of an object from a defined starting point.
I'm analising satellite images for volcanic purposes, so I have the position (in terms of lat and lon) of my starting point. My final goal is to calculate the max distance traveled by a lava flow, which can creates different morpholigies, including curves or ingent lava fields.
I can identify which pixels of the image are related to the lava flow, but I need to create a script that calculate the maximum distance it reached. Currently I'm trying to work with binary images, also trying to explore the bwskel function, but didn't find a solution yet.
Here my matrices and variables: LAT and LON are the latitude and longitude matrices related to the LavaField_example matrices, that is a Logical matrix with 1 for the pixels occupied by lava. This is a real example derived by satellite images acquired during the eruption of Piton de la Fournaise in Sep-Oct 2022, I need the max lenght of the main lava field (the other small cluster must be excluded).
starting pixel
LATstart: -21.2429
LONstart: 55.7092
index (in the LavaField matrix): 9046
0 Comments
Accepted Answer
Antoni Garcia-Herreros
on 17 May 2023
Edited: Antoni Garcia-Herreros
on 17 May 2023
Hello Adele,
load('LavaField_example.mat')
thr=10; % Threshold to filter small lava regions
%% Max length of the whole lava field
r=regionprops('table',BWcumL,'Area','MaxFeretProperties');
r=r(r.Area>thr,:); % Retain only the large lava regions
r.MaxFeretDiameter % Max length of the main lava field
% Max distance the lava has flown from the center of the crater
B = bwboundaries(BWcumL);
Bpoints=B{1,1};
[xi,yi]=ind2sub([134,134],9046) % Position of the crater
D=pdist2(Bpoints,[xi,yi]); % Distance from the crater to the boundary
[MAX_FLOWN_DIST,n]=max(D);
% Plot
imshow(BWcumL)
hold on
A=r.MaxFeretCoordinates{1}; % Coordinates of the start-end point
plot(A(:,1),A(:,2),'-r')
plot(xi,yi,'o')
plot([Bpoints(n,2) xi],[Bpoints(n,1) yi])
l=legend({'MAX lava field length', 'Crater','Max lava field length from the crater'});
Hope this helps!
2 Comments
More Answers (0)
See Also
Categories
Find more on Seismology in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!