Skip to content

Error in generate_left_ventricle_segments and get_com functions #308

@hannahalme

Description

@hannahalme

Hello,

Thank you for this useful library! I have used platipy for calculating the AHA-17 segments in cardiac CT data. I noticed that for some patients, the function generate_left_ventricle_segments fails, giving the following error:

File ~/Desktop/segmentointi/test_env/lib/python3.13/site-packages/platipy/imaging/utils/ventricle.py:397, in generate_left_ventricle_segments(contours, label_left_ventricle, label_left_atrium, label_right_ventricle, label_heart, myocardium_thickness_mm, hole_fill_mm, optimiser_tol_degrees, optimiser_max_iter, min_area_mm2, verbose)
    395 for n in range(inf_limit_lv, apical_extent):
    396     lv_com_apical_list.append(get_com(working_contours[label_left_ventricle][:, :, n]))
--> 397     rv_com_apical_list.append(get_com(working_contours[label_right_ventricle][:, :, n]))
    399 lv_com_apical = np.mean(lv_com_apical_list, axis=0)
    400 rv_com_apical = np.mean(rv_com_apical_list, axis=0)

File ~/Desktop/segmentointi/test_env/lib/python3.13/site-packages/platipy/imaging/label/utils.py:86, in get_com(label, as_int, real_coords)
     84     if as_int:
     85         print(com)
---> 86         com = [int(i) for i in com]
     88 return com

ValueError: cannot convert float NaN to integer

To me, it seems that the get_com function tries to calculate the center of mass slice by slice for the left and right ventricle, but fails since some of the slices in the right ventricle contain only zeros (that's why the center of mass is NaN).

Do you think this error could be resolved by allowing the center of mass to be zero for some slices, or would it break some essential functionality? Does the function assume that left and right ventricle have equal length (from inf_limit_lv to apical_extent)? I suppose this is rarely the case in reality.

Thank you for your help!

Best,
Hanna

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions