contour_longest_distance#
- medicalimageanalysis.utils.roi.statistics.contour_longest_distance(contours, exact=False)[source]
Longest in-plane distance across a stack of contours, in mm.
Each contour is handled on its own and the largest result is returned. A candidate segment only counts if it lies inside the contour polygon, so the distance never crosses a concave notch. (N, 3) contours are projected onto their best-fit plane first.
- Parameters:
- Returns:
Longest internal distance in mm, or 0.0 if no valid segment is found.
- Return type:
Examples
Diagonal of a 20 x 10 mm rectangle:
>>> import numpy as np >>> from medicalimageanalysis.utils.roi.statistics import contour_longest_distance >>> rectangle = np.array([[0, 0], [20, 0], [20, 10], [0, 10]]) >>> round(contour_longest_distance([rectangle], exact=True), 2) 22.36
The same rectangle as a 3D contour lying on z = 5 mm:
>>> rectangle_3d = np.c_[rectangle, np.full(4, 5.0)] >>> round(contour_longest_distance([rectangle_3d]), 2) 22.36
Largest value across a stack of slices:
>>> small = rectangle * 0.5 >>> round(contour_longest_distance([small, rectangle]), 2) 22.36