PyContour
- class multimodars.PyContour(id, original_frame, points, centroid, aortic_thickness, pulmonary_thickness, kind)
Bases:
objectPython representation of a 3D contour.
- id
Contour identifier (sequence number).
- Type:
int
- original_frame
Frame index from which this contour originates.
- Type:
int
- points
Ordered list of contour points.
- Type:
list of PyContourPoint
- centroid
(x, y, z)centroid coordinates of the contour.- Type:
tuple of float
- aortic_thickness
Aortic wall thickness at this contour, if available.
- Type:
float or None
- pulmonary_thickness
Pulmonary wall thickness at this contour, if available.
- Type:
float or None
- kind
String representation of the contour type (e.g.
"Lumen").- Type:
str
Examples
>>> contour = PyContour( ... id=0, ... points=[point1, point2, ...], ... centroid=(1.0, 1.0, 1.0) ... )
- compute_centroid()
Calculate the contour centroid by averaging all point coordinates.
Examples
>>> contour.compute_centroid()
- find_closest_opposite()
Find the closest points on opposite sides of the contour.
- Returns:
points (tuple of PyContourPoint) – Pair
(p1, p2)of opposing contour points with minimum distance.distance (float) – Euclidean distance between p1 and p2.
Examples
>>> (p1, p2), distance = contour.find_closest_opposite()
- find_farthest_points()
Find the two farthest points in the contour.
- Returns:
points (tuple of PyContourPoint) – Pair
(p1, p2)of the two most distant points.distance (float) – Euclidean distance between p1 and p2.
Examples
>>> (p1, p2), distance = contour.find_farthest_points()
- get_area()
Get the area of the current contour using the shoelace formula.
- Returns:
Area of the contour in the units of the original data (e.g. mm²).
- Return type:
float
Examples
>>> area = contour.get_area()
- get_elliptic_ratio()
Get the elliptic ratio of the current contour.
- Returns:
Ratio of the farthest-points distance divided by the closest-opposite-points distance.
- Return type:
float
Examples
>>> elliptic_ratio = contour.get_elliptic_ratio()
- points_as_tuples()
Return contour points as a list of
(x, y, z)tuples.- Returns:
Each element is
(x, y, z)coordinates of one contour point.- Return type:
list of tuple of float
Examples
>>> contour.points_as_tuples() [(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)]
- rotate(angle_deg)
Rotate the contour around its own centroid by an angle in degrees.
- Returns:
New contour rotated around its centroid.
- Return type:
Examples
>>> contour = contour.rotate(20)
- sort_contour_points()
Sort points within the contour in counterclockwise order.
The point with the highest y-coordinate receives index 0; all remaining points are ordered counterclockwise.
- Returns:
New contour with rearranged point indices.
- Return type:
Examples
>>> contour = contour.sort_contour_points()
- translate(dx, dy, dz)
Translate the contour by
(dx, dy, dz)coordinates.- Parameters:
dx (float) – Translation in the x-direction.
dy (float) – Translation in the y-direction.
dz (float) – Translation in the z-direction.
- Returns:
New contour translated by
(dx, dy, dz).- Return type:
Examples
>>> contour = contour.translate((0.0, 1.0, 2.0))