How to calculate the total length of all the lines in this image (with grid)?

조회 수: 8 (최근 30일)
Bunnyo
Bunnyo 2022년 8월 13일
댓글: Benjamin Thompson 2022년 8월 18일
Hello,
Is there a way to calculate the total distance/length of all the red lines in this image (only red lines)?
Those red lines are like trajectory, and each cyan grid's edge can be consider as 1 unit.
[Calculating each line's length and adding them all up isn't going to work because later on i will have more red lines :( ]
Thank you in advance!!!

답변 (1개)

Benjamin Thompson
Benjamin Thompson 2022년 8월 15일
편집: Benjamin Thompson 2022년 8월 15일
You can use colorThresholder to help isolate the red pixels and then simply count all of them in the resulting mask image using the sum function. colorThresholder generates script code which I have attached, with a small manual edit to get just the BW mask image as the output. Apply a scale factor to the result if your red lines are wider than one pixel.
sum(redPixelMask(A), 'all')
ans =
114805
  댓글 수: 2
Bunnyo
Bunnyo 2022년 8월 18일
Hi, thank you for your answer! I'm kind of confused on this "if your red lines are wider than one pixel" part. How should i apply this scale factor?
Benjamin Thompson
Benjamin Thompson 2022년 8월 18일
A pixel count is more a measure of area so if your lines are 2 pixels wide, the measurement will be 2 times too large as a distance estimate.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by