diff --git a/deepaneseg/data/io.py b/deepaneseg/data/io.py index 1c6b52e..1ef7b8f 100644 --- a/deepaneseg/data/io.py +++ b/deepaneseg/data/io.py @@ -253,8 +253,7 @@ def extract_points_from_patient(patient, r=20, nb_points=100, outfile="points.cs d = json.load(f) vol, vox2met = read_nii_from_file(os.path.join(patient, d["noskull volume"])) print("Extracting points") - forbidden_points = read_points_from_csv(os.path.join(patient, d["pts aneurysm"])) - fp = points_to_spheres(forbidden_points)[:, :-1] # drop radii + fp = read_aneurysm_spheres(patient)[:, :3] # aneurysm centers, none for a patient without aneurysm q = None if random_points: min_threshold, max_threshold = np.percentile(vol[vol > 0], 0), np.percentile(vol[vol > 0], 100) diff --git a/deepaneseg/volume/selection.py b/deepaneseg/volume/selection.py index d1ebf4d..4b320e4 100644 --- a/deepaneseg/volume/selection.py +++ b/deepaneseg/volume/selection.py @@ -74,7 +74,7 @@ def select_points( removed = np.zeros(len(v), dtype=bool) tree = skn.KDTree(p) - if not forbidden_points is None: + if forbidden_points is not None and len(forbidden_points): if len(forbidden_points.shape) == 1: forbidden_points = forbidden_points[np.newaxis, :] for i in tree.query_radius(forbidden_points, r): diff --git a/tests/test_healthy_patients.py b/tests/test_healthy_patients.py index 2b67c21..5ce6e15 100644 --- a/tests/test_healthy_patients.py +++ b/tests/test_healthy_patients.py @@ -45,3 +45,21 @@ def test_adam_evaluation_on_healthy_patient(): tp, fp, _, _ = adam_evaluation(pred, np.eye(4), NO_SPHERES) assert (tp, fp) == (0, 1) + + +def test_points_are_extracted_for_a_patient_without_aneurysm(tmp_path): + import json + + import nibabel as ni + import pandas as pd + + from deepaneseg.data.io import extract_points_from_patient + + vol = np.random.default_rng(0).random((40, 40, 40)).astype(np.float32) + ni.save(ni.Nifti1Image(vol, np.diag([0.5, 0.5, 0.5, 1.0])), tmp_path / "noskull.nii.gz") + (tmp_path / "config.json").write_text(json.dumps({"noskull volume": "noskull.nii.gz"})) + + extract_points_from_patient(str(tmp_path), r=4, nb_points=5) + + points = pd.read_csv(tmp_path / "points.csv") + assert set(points["type"]) == {"Vessel", "Parenchyma"} and len(points) == 10