Skip to content

Commit d4e1b27

Browse files
authored
Merge pull request #108 from Hendrik-code/development_robert
Development robert
2 parents 1e24731 + 49169f4 commit d4e1b27

7 files changed

Lines changed: 33 additions & 8 deletions

File tree

TPTBox/core/nii_poi_abstract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import sys
4-
import warnings
54
from dataclasses import dataclass
65
from typing import TYPE_CHECKING, Any
76

@@ -495,6 +494,7 @@ def local_to_global(self, x: COORDINATE) -> tuple:
495494
Returns:
496495
tuple: World-space coordinate rounded to 7 decimal places.
497496
"""
497+
# TODO ITK version
498498
a = self.rotation @ (np.array(x) * np.array(self.zoom)) + self.origin
499499
return tuple(round(float(v), 7) for v in a)
500500

TPTBox/core/nii_wrapper.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,8 +1202,7 @@ def resample_from_to(self, to_vox_map:Image_Reference|Has_Grid|tuple[SHAPE,AFFIN
12021202
pad = tuple((int(b), int(a)) for b, a in zip(pad_before, pad_after))
12031203
ret = s.apply_pad(pad, mode=mode,inplace=inplace,verbose=verbose)
12041204

1205-
#TODO SET raise_error=False before committing
1206-
valid = ret.assert_affine(mapping,raise_error=True,origin_tolerance=0.0001,error_tolerance=0.0001,shape_tolerance=0)
1205+
valid = ret.assert_affine(mapping,raise_error=False,origin_tolerance=0.0001,error_tolerance=0.0001,shape_tolerance=0)
12071206
if valid:
12081207
log.print(f"resample_from_to only needs padding/cropping {pad}",verbose=verbose)
12091208
ret.affine = mapping.affine #remove floating point error
@@ -2446,7 +2445,7 @@ def to_stls(
24462445

24472446
def to_stl(
24482447
self: NII,
2449-
label: int,
2448+
label: int|Enum|Sequence[int]|Sequence[Enum],
24502449
out_path: Path | dict[int, Path] | None = None,
24512450
bb: tuple | None = None,
24522451
to_world: bool = True,
@@ -2499,7 +2498,6 @@ def to_stl(
24992498
not support per-vertex attributes such as scalar values from marching cubes.
25002499
"""
25012500
from stl import mesh
2502-
25032501
seg = self.extract_label(label)
25042502
# Prepare binary mask
25052503
seg_arr = np.pad(seg.clamp(0, 1).get_array(), 1)

TPTBox/core/poi_fun/poi_abstract.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,12 +1030,16 @@ def join_left(self, pois: Self, inplace=False, _right_join=False) -> Self:
10301030
Self: The combined set of centroids, either in-place or as a new set, depending on the 'inplace' parameter.
10311031
"""
10321032
ctd_list = self.centroids
1033+
if "label_name" in pois.info and "label_name" not in self.info:
1034+
self.info["label_name"] = {}
10331035
if not inplace:
10341036
ctd_list = ctd_list.copy()
10351037
for x, y, c in pois.items():
10361038
if (x, y) in self and not _right_join:
10371039
continue
10381040
ctd_list[x, y] = c
1041+
if "label_name" in pois.info and f"({x}, {y})" in pois.info["label_name"]:
1042+
self.info["label_name"][f"({x}, {y})"] = pois.info["label_name"][f"({x}, {y})"]
10391043
if inplace:
10401044
return self
10411045
return self.copy(ctd_list)

TPTBox/core/poi_fun/save_load.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ def convert(o):
135135
return str(o.absolute())
136136
raise TypeError(type(o))
137137

138-
with open(out_path, "w") as f:
139-
json.dump(json_object, f, default=convert, indent=4)
138+
try:
139+
with open(out_path, "w") as f:
140+
json.dump(json_object, f, default=convert, indent=4)
141+
except TypeError:
142+
Path(out_path).unlink(missing_ok=True)
143+
raise
140144
log.print("POIs saved:", out_path, print_add, ltype=Log_Type.SAVE, verbose=verbose)
141145

142146

TPTBox/core/vert_constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,8 +1223,15 @@ def save_as_name(cls) -> bool:
12231223
Rib_Left = 63
12241224
Rib_Right = 64
12251225
# 66-80 Free
1226+
# Sacrum Subregions
1227+
Sacrum_Sacral_Ala_Left = 70
1228+
Sacrum_Sacral_Ala_Right = 71
1229+
Sacrum_Posterior_Sacral_Elements = 72
1230+
Sacrum_Body = 73
1231+
Sacrum_Endplate = 74
12261232
# Muscle inserts
12271233
# https://www.frontiersin.org/articles/10.3389/fbioe.2022.862804/full
1234+
Metal = 80
12281235
# 81-91
12291236
Muscle_Inserts_Spinosus_Process = 81
12301237
Muscle_Inserts_Transverse_Process_Left = 83

TPTBox/registration/_deformable/multilabel_segmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def transform_nii(self, nii_atlas: NII, allow_only_same_grid_as_moving: bool = T
325325
nii_reg = self.reg_deform.transform_nii(nii_atlas)
326326
if nii_reg.seg:
327327
nii_reg.set_dtype_("smallest_uint")
328-
out = nii_reg.resample_from_to(self.target_grid_org)
328+
out = nii_reg.resample_from_to(self.target_grid_org, mode="constant")
329329
if self.same_side:
330330
return out
331331
axis = out.get_axis("R")

unit_tests/test_testsamples.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def test_POIs_CT(self):
113113
Location.Vertebral_Body_Endplate_Inferior,
114114
Location.Rib_Left,
115115
Location.Rib_Right,
116+
Location.Sacrum_Sacral_Ala_Left,
117+
Location.Sacrum_Sacral_Ala_Right,
118+
Location.Sacrum_Posterior_Sacral_Elements,
119+
Location.Sacrum_Body,
120+
Location.Sacrum_Endplate,
121+
Location.Metal,
116122
]
117123
self.make_POIs(vert_nii, subreg_nii, label, ignore_list)
118124

@@ -134,6 +140,12 @@ def test_POIs_MR(self):
134140
Location.Vertebral_Body_Endplate_Inferior,
135141
Location.Rib_Left,
136142
Location.Rib_Right,
143+
Location.Sacrum_Sacral_Ala_Left,
144+
Location.Sacrum_Sacral_Ala_Right,
145+
Location.Sacrum_Posterior_Sacral_Elements,
146+
Location.Sacrum_Body,
147+
Location.Sacrum_Endplate,
148+
Location.Metal,
137149
]
138150
self.make_POIs(vert_nii, subreg_nii, label, ignore_list)
139151

0 commit comments

Comments
 (0)