Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions deepaneseg/data/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion deepaneseg/volume/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_healthy_patients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading