System designHow-to

How to measure crack endpoint distance from an image

Measure crack endpoint distance from a cleaned mask, reject branches, calculate pixel separation, and convert it to calibrated physical units.

LumaSpec Vision10 min read Share on LinkedIn

On this page 10 sections
  1. 01Decide what the measurement means
  2. 02What you need before processing
  3. 03Process the mask and identify two endpoints
    1. Handling short spurs
  4. 04Calculate pixel and physical distance
  5. 05Worked example and uncertainty check
  6. 06Choose acquisition hardware only where it helps
  7. 07Verify the measurement before using it
  8. 08When endpoint distance is the wrong answer
  9. 09Final checklist and next step
  10. 10Questions

A segmented crack mask gives you a region, not automatically a pair of measurement points. Thick edges, isolated pixels, and small branches can all produce misleading endpoints. This procedure is for measuring the straight-line separation between two crack tips in a single image. You will clean the mask, extract a centerline, validate its endpoints, and calculate a distance with an explicit calibration and uncertainty check.

Decide what the measurement means

Endpoint distance is the straight line connecting two selected crack tips. It is not the distance traced along the crack, the perimeter of the segmented region, or the diagonal of its bounding box.

Measurement Definition Suitable use
Endpoint distance Straight-line separation between two tips Overall tip separation
Crack-path length Distance following a defined centerline route Length of a curved crack
Bounding-box diagonal Diagonal of the enclosing rectangle Coarse spatial extent, not tip separation
Component-centroid distance Separation between centers of separate regions Spacing between objects, not tips of one crack

For a curved crack, endpoint distance is shorter than its centerline path. A branching crack also has more than two possible tips, so the measurement needs a branch-selection rule.

The related procedure for edge endpoint detection near the image center addresses endpoint selection using a positional constraint. Here, the objective is different: identify the two tips of a selected crack and measure their separation, wherever they appear.

Record that definition before adjusting thresholds. Otherwise, processing changes can silently change which physical feature you measure.

What you need before processing

Keep the original grayscale image, the binary crack mask, and the coordinate relationship between them. A mask resized or cropped without its transformation information cannot safely provide coordinates in the original image.

Start with these inputs:

  • A binary mask in which crack pixels are foreground and background pixels are excluded.
  • A region of interest containing the intended crack and some surrounding background.
  • A stated rule for selecting the crack when several components are present.
  • A calibration for physical measurements, or a clear decision to report pixels only.
  • Saved examples covering straight, curved, broken, and branching cracks.

Display the mask over the original image before measuring anything. Confirm that the segmented tips correspond to visible crack tips rather than shadows, texture, or the image boundary.

A tip touching the image boundary is usually censored: the crack may continue beyond the frame. Mark that measurement as incomplete unless your inspection definition specifically measures the visible portion.

Process the mask and identify two endpoints

Use the following numbered sequence as a starting workflow. Preserve intermediate images so that a wrong distance can be traced to a specific operation.

  1. Restrict processing to the intended region. Exclude labels, edges, and unrelated cracks using the region of interest. Do not select the largest component automatically unless the inspection guarantees that it represents the target crack.

  2. Label connected foreground components. Choose a connectivity convention and keep it consistent. With 8-connectivity, diagonally touching foreground pixels belong to the same component. Inspect cases where neighboring cracks almost touch.

  3. Remove isolated foreground debris. Reject components below a validated area threshold. Base this threshold on the smallest real feature you must retain, not on whichever setting makes one image look clean.

  4. Repair gaps only when the evidence supports it. Morphological closing can connect interrupted regions, but it can also join separate cracks and extend tips. Save the mask before repair and compare the endpoint locations afterward. Avoid filling background regions indiscriminately.

  5. Thin the selected component to a skeleton. Use a topology-preserving skeletonization or thinning operation suitable for binary images. The intended result is a narrow centerline that retains the component's connections. Different methods can produce different terminal branches, especially around blunt tips.

  6. Find endpoint candidates. On a one-pixel-wide skeleton, an endpoint candidate normally has exactly one foreground neighbor within its 8-neighbor neighborhood. A pixel with no neighbors is isolated, not a valid crack endpoint.

  7. Resolve branches and validate the chosen pair. If exactly two candidates remain, overlay both on the original image. If more remain, inspect branches before pruning or choosing a route. If none remain, check for loops, incomplete thinning, or segmentation that connects features incorrectly.

A raw neighborhood count is a useful first test, not a complete topology analysis. Diagonal contacts and clustered junction pixels can create extra graph connections. Use a graph representation that handles junction clusters consistently when branch lengths matter.

Handling short spurs

Small side branches often come from rough segmentation boundaries. You may prune a terminal branch whose length is below a validated threshold, measured from its tip to its first junction.

For example, a trial threshold of 3 pixels is defensible only if it cannot remove a genuine feature required by the inspection. Compare the pruned result against annotated examples, including the shortest real cracks.

For a branched component, one possible rule is to select the endpoint pair with the greatest shortest-path distance through the skeleton. Weight horizontal and vertical steps as 1 and diagonal steps as approximately 1.414. This identifies a long connected route, but does not prove that its endpoints are the intended physical tips.

Calculate pixel and physical distance

Store endpoints as coordinates in the same image coordinate system. Array indexing often uses row and column, while geometric coordinates use horizontal x and vertical y. Make that conversion explicit.

For endpoints A and B, calculate:

Delta_x = x_B - x_A Delta_y = y_B - y_A d_pixels = sqrt(Delta_x^2 + Delta_y^2)

A common mistake is subtracting one endpoint's row from the other endpoint's column. Another is mixing coordinates from a cropped mask with coordinates from the full image.

For a calibrated, effectively front-facing plane with equal horizontal and vertical scale:

d_physical = s * d_pixels

Here, s is the object-plane scale, such as millimeters per pixel. With different constant scales along the image axes:

d_physical = sqrt((s_x * Delta_x)^2 + (s_y * Delta_y)^2)

That second formula does not correct general perspective distortion. For a tilted planar surface, correct lens distortion as appropriate and map both endpoints into calibrated plane coordinates. Calculate their distance in that plane rather than multiplying image distance by one global scale.

Use the procedure for camera calibration for length measurement when establishing that coordinate mapping. The explanation of object-space pixel size helps distinguish sensor sampling from the size represented by a pixel on the part.

A curved surface presents a further limit: a single planar calibration does not recover distance over its surface. State whether your output is an image-plane distance, a distance in a calibrated plane, or a true spatial measurement.

Worked example and uncertainty check

Suppose the validated endpoints in an illustrative image are A = (40, 70) and B = (340, 470), expressed in pixels.

Delta_x = 340 - 40 = 300 pixels Delta_y = 470 - 70 = 400 pixels d_pixels = sqrt(300^2 + 400^2) d_pixels = sqrt(250000) = 500 pixels

Assume a suitable planar calibration gives a scale of 0.020 mm per pixel:

d_physical = 500 pixels * 0.020 mm/pixel d_physical = 10.0 mm

The arithmetic does not establish the accuracy. Segmentation, tip definition, calibration, focus, and surface geometry still affect the answer.

If each endpoint has a bounded positional error of at most 1 pixel in any direction, their separation can differ by up to 2 pixels. At the illustrative scale, that contribution is bounded by:

endpoint_distance_error <= 2 * 1 pixel * 0.020 mm/pixel endpoint_distance_error <= 0.040 mm

This is a conservative bound for endpoint localization alone. Calibration and geometric errors need separate treatment. Do not report that bound as the complete measurement uncertainty.

For acquisition planning, suppose a 40 mm field of view must provide a nominal sampling of 0.020 mm per pixel:

required_horizontal_pixels = 40 mm / 0.020 mm/pixel required_horizontal_pixels = 2000 pixels

This gives a sampling requirement, not a guarantee of tip localization accuracy. Use the camera resolution calculator to explore field-of-view and pixel-count tradeoffs.

Camera resolution for the smallest feature
Units
Pixels needed
–
Sensor size
– MP
Smallest sensor that fits
–
Pixel on the part
– mm
Pixels across the feature, that sensor
–

Pixels needed = field / feature × pixels per feature on each axis (field incl. margin). The lens must resolve the pixels too: Nyquist = 1000 / (2 × pixel µm) lp/mm.

Find cameras with enough pixels Open the full calculator

Choose acquisition hardware only where it helps

Stable images matter more than adding pixels to an unstable mask. Check illumination, focus, motion, and exposure before replacing the camera. A blurred tip cannot be recovered reliably just by enlarging its image.

For a stationary part, area scan cameras can provide the image used by this workflow. Use the camera finder to compare interface, shutter, and sampling needs after establishing the measurement geometry.

The LS-CMR-0053 uses a GigE interface and a rolling shutter. It is a candidate to evaluate against your acquisition requirements, not evidence of a particular measurement accuracy.

Area scan cameras12 MP GigE area scan camera, IMX226, 1/1.7" rolling shutter, 9 fps (LS-CMR-0053)LS-CMR-0053
Sensor format
1/1.7"
Lens mount
C-mount
Interface
GigE
Resolution
12 MP
$560.00View partBuild a system with it

The LS-CMR-0166 uses a USB3 interface and a rolling shutter. Evaluate the complete acquisition arrangement before choosing an interface.

Area scan cameras12 MP USB3 area scan camera, IMX226, 1/1.7" rolling shutter, 30 fps, 4000 × 3000 resolution (LS-CMR-0166)LS-CMR-0166
Sensor format
1/1.7"
Interface
USB3
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

Both examples require attention to movement because rolling-shutter timing can distort moving features. If the part moves during acquisition, assess exposure blur and shutter-related geometric distortion separately. Do not assume that a short exposure alone removes every motion-related error.

Verify the measurement before using it

Validation should test the measurement definition as well as the calculation. A perfectly implemented distance formula can still connect the wrong tips.

Use a small, labeled evaluation set with these cases:

  • Straight crack: verify the two selected tips and compare against manually marked coordinates.
  • Curved crack: confirm that endpoint distance remains distinct from centerline length.
  • Short side branch: check whether pruning removes noise without deleting the intended tip.
  • Broken mask: verify that gap repair does not connect unrelated features.
  • Border contact: confirm that the output is marked incomplete.
  • No crack or multiple cracks: verify that the software returns an explicit status rather than an arbitrary distance.

Save the selected component, skeleton, endpoint count, endpoint coordinates, calibration identifier, distance, and quality status. Overlay the connecting line on the original image for review.

Repeat segmentation with modest threshold changes. If the reported distance moves substantially, the endpoint definition or image contrast needs attention before you trust the number.

When comparing successive images, keep the component identity and coordinate reference consistent. The procedure for crack horizontal growth measurement explains the different question of tracking directional change over time.

When endpoint distance is the wrong answer

Use centerline path length when the requirement concerns how far a crack travels along a curved route. Use a directional projection when the requirement concerns horizontal or vertical growth. Use a documented branch rule when several genuine tips exist.

A crack that doubles back can have a long path and a small endpoint distance. A closed segmented loop has no natural pair of tips. A crack disappearing beneath another feature may have visible endpoints that are not its physical endpoints.

Skeletonization also does not create subpixel accuracy. Pixel-center endpoints are discrete estimates, and thinning may shift their locations relative to a blunt or irregular visible tip. A separate, validated tip-fitting method may be needed when that shift is significant.

Report ambiguous cases as ambiguous. Returning a numeric value for every image can hide failure modes that matter more than numerical precision.

Final checklist and next step

Before accepting the workflow, confirm:

  • The output is explicitly defined as straight-line tip separation.
  • Mask cleanup has been checked for endpoint movement.
  • The component and branch-selection rules are documented.
  • Both endpoints use the same coordinate system.
  • Calibration matches the measured plane and image processing.
  • Border contact and ambiguous topology produce a quality status.
  • Repeatability has been checked on representative images.

If existing images pass these checks, improve the software and validation before changing hardware. If sampling or acquisition stability is insufficient, start with the camera configurator. For help reviewing the imaging geometry and endpoint criteria together, use application support.

Questions

How do you find the two endpoints of a crack mask?

Thin the selected binary component to a centerline, then identify skeleton pixels with one foreground neighbor. Validate those candidates against the original image. Extra candidates usually require branch analysis, while missing candidates can indicate loops, connected features, or an unsuitable skeleton.

Is endpoint distance the same as crack length?

No. Endpoint distance measures straight-line separation between two selected tips. Centerline length follows the crack's route and is usually longer for a curved crack. Define which quantity your inspection requires before selecting endpoints or applying a pass/fail threshold.

What should happen when the skeleton has more than two endpoints?

Use a documented branch-selection rule rather than accepting an arbitrary pair. You can remove validated short spurs or evaluate routes through a skeleton graph. If several genuine branches remain and the required pair is unclear, return an ambiguous status for review.

How do you convert endpoint distance from pixels to millimeters?

Multiply by a calibrated object-plane scale only when that scale is valid across the measurement region. For perspective views of a plane, transform both endpoints into calibrated plane coordinates first. A single image with planar calibration cannot establish distance over an unknown curved surface.

Does a higher-resolution camera guarantee more accurate crack measurements?

No. Camera resolution determines sampling, but image contrast, focus, motion, segmentation, tip definition, and calibration also affect accuracy. Validate the full workflow using representative cracks and known geometry rather than treating pixel count as a measurement specification.