Skip to content

Commit 4399e84

Browse files
committed
feat: add junction cleanup
1 parent e9f5f90 commit 4399e84

6 files changed

Lines changed: 364 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ readme = "README.md"
77
requires-python = ">=3.13"
88
dependencies = [
99
"argcomplete>=3.6.0",
10+
"networkx>=3.4",
1011
"numba>=0.65.0",
1112
"numpy>=2.4.4",
1213
"pillow>=12.2.0",

uv.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vesskel/_napari.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def _extraction_params(
4646
extract_summary: bool = True,
4747
include_fractal: bool = False,
4848
include_vessel_radius: bool = False,
49+
junction_cleanup: bool = False,
50+
cleanup_threshold_factor: float = 2.5,
4951
) -> None:
5052
return None
5153

@@ -56,6 +58,15 @@ def _extraction_params(
5658
extract_branch_text={"annotation": bool, "value": True},
5759
extract_summary={"annotation": bool, "value": True},
5860
include_fractal={"annotation": bool, "value": False},
61+
junction_cleanup={"annotation": bool, "value": False},
62+
cleanup_threshold_factor={
63+
"annotation": float,
64+
"value": 2.5,
65+
"widget_type": "FloatSpinBox",
66+
"min": 1.0,
67+
"max": 10.0,
68+
"step": 0.1,
69+
},
5970
)
6071

6172
# ---------- output parameters (magicgui) ----------
@@ -109,6 +120,15 @@ def _output_params(
109120

110121
advanced_group.append(self.include_vessel_radius_widget)
111122

123+
self.junction_cleanup_widget = extraction_gui.junction_cleanup
124+
self.junction_cleanup_widget.label = "Collapse triangle junction artifacts"
125+
126+
self.cleanup_threshold_widget = extraction_gui.cleanup_threshold_factor
127+
self.cleanup_threshold_widget.label = "Cleanup threshold factor"
128+
129+
advanced_group.append(self.junction_cleanup_widget)
130+
advanced_group.append(self.cleanup_threshold_widget)
131+
112132
# ============================================================
113133
# Output Settings (CLI file export options)
114134
# ============================================================
@@ -172,13 +192,16 @@ def _output_params(
172192
# ------------------------------------------------------------------
173193

174194
def _get_current_pipeline_config(self) -> PipelineConfig:
195+
junction_cleanup = self.junction_cleanup_widget.value
175196
return PipelineConfig(
176197
extraction=ExtractionConfig(
177198
branches=self.extract_branches_widget.value,
178199
branch_text=self.extract_branch_text_widget.value,
179200
summary=self.extract_summary_widget.value,
180201
fractal_dimension=self.include_fractal_widget.value,
181202
vessel_radius=self.include_vessel_radius_widget.value,
203+
junction_cleanup=junction_cleanup,
204+
cleanup_threshold_factor=self.cleanup_threshold_widget.value,
182205
),
183206
output=OutputConfig(
184207
write_skeleton_npy=self.write_skeleton_npy_widget.value,
@@ -196,6 +219,8 @@ def _set_pipeline_config(self, config: PipelineConfig) -> None:
196219
self.extract_summary_widget.value = e.summary
197220
self.include_fractal_widget.value = e.fractal_dimension
198221
self.include_vessel_radius_widget.value = e.vessel_radius
222+
self.junction_cleanup_widget.value = e.junction_cleanup
223+
self.cleanup_threshold_widget.value = e.cleanup_threshold_factor
199224

200225
o = config.output
201226
self.write_skeleton_npy_widget.value = o.write_skeleton_npy

vesskel/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class ExtractionConfig:
2929
summary: bool = True
3030
fractal_dimension: bool = False
3131
vessel_radius: bool = False
32+
junction_cleanup: bool = False
33+
cleanup_threshold_factor: float = 2.5
3234

3335
def to_dict(self) -> dict[str, Any]:
3436
return {
@@ -37,6 +39,8 @@ def to_dict(self) -> dict[str, Any]:
3739
"summary": self.summary,
3840
"fractal_dimension": self.fractal_dimension,
3941
"vessel_radius": self.vessel_radius,
42+
"junction_cleanup": self.junction_cleanup,
43+
"cleanup_threshold_factor": self.cleanup_threshold_factor,
4044
}
4145

4246
@classmethod
@@ -48,6 +52,8 @@ def from_dict(cls, data: dict[str, Any]) -> ExtractionConfig:
4852
summary=data.get("summary", True),
4953
fractal_dimension=data.get("fractal_dimension", False),
5054
vessel_radius=data.get("vessel_radius", False),
55+
junction_cleanup=data.get("junction_cleanup", False),
56+
cleanup_threshold_factor=data.get("cleanup_threshold_factor", 2.5),
5157
)
5258

5359

0 commit comments

Comments
 (0)