Measure the distance of a curve within an image

27 views (last 30 days)
I am trying to learn how to take measurements of different aspects in an image. With the image provided, how would I measure the length of the curved blue line and the diameter of the green circle if the hight of the red box is 3 meters. I will post my code if I can actually get something working. Thank you.

Answers (2)

Benjamin Thompson
Benjamin Thompson on 25 Jan 2022
You could use imshow to load and display the image, then ginput get get a series of manually selected points on the line. If you have the image processing toolbox, imtool has a bit more image analysis capabilities, and colorThresholder can be used to create a blue color mask so you can get the list of pixels that are part of the blue line and then do further math on those pixels positions.

Image Analyst
Image Analyst on 25 Jan 2022
I'd just get a mask of the blue line. Like
[r, g, b] = imsplit(rgbImage);
blueMask = r == 0 & g == 0 & b == 255;
or you can use the Color Thresholder app on the Apps tab of the tool ribbon.
If the line is known to be a single pixel wide then you can just count the number of non-zero pixels.
lineLength = nnz(blueMask);
If the line is thick, then you can get the skeleton image with bwskel first
blueMask = bwskel(blueMask);
lineLength = nnz(blueMask);

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!