Skip to content

Commit 3ab0655

Browse files
authored
Make extraction of the largest connected component optional (#305)
1 parent 9af7c19 commit 3ab0655

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

diffdrr/visualization.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def drr_to_mesh(
181181
subject: Subject, # torchio.Subject with a `volume` attribute
182182
method: str, # Either `surface_nets` or `marching_cubes`
183183
threshold: float = 150, # Min value for marching cubes (Hounsfield units)
184+
extract_largest: bool = True, # Extract the largest connected component from the mesh
184185
verbose: bool = True, # Display progress bars for mesh processing steps
185186
):
186187
"""
@@ -190,7 +191,7 @@ def drr_to_mesh(
190191
191192
The mesh processing steps are:
192193
193-
1. Keep only largest connected components
194+
1. Keep only largest connected components (optional)
194195
2. Smooth
195196
3. Decimate (if `method=="marching_cubes"`)
196197
4. Fill any holes
@@ -229,7 +230,8 @@ def drr_to_mesh(
229230
mesh = mesh.transform(subject.volume.affine.squeeze())
230231

231232
# Preprocess the mesh
232-
mesh.extract_largest(inplace=True, progress_bar=verbose)
233+
if extract_largest:
234+
mesh.extract_largest(inplace=True, progress_bar=verbose)
233235
mesh.point_data.clear()
234236
mesh.cell_data.clear()
235237
mesh.smooth_taubin(

notebooks/api/04_visualization.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@
286286
" subject: Subject, # torchio.Subject with a `volume` attribute\n",
287287
" method: str, # Either `surface_nets` or `marching_cubes`\n",
288288
" threshold: float = 150, # Min value for marching cubes (Hounsfield units)\n",
289+
" extract_largest: bool = True, # Extract the largest connected component from the mesh\n",
289290
" verbose: bool = True, # Display progress bars for mesh processing steps\n",
290291
"):\n",
291292
" \"\"\"\n",
@@ -295,7 +296,7 @@
295296
"\n",
296297
" The mesh processing steps are:\n",
297298
"\n",
298-
" 1. Keep only largest connected components\n",
299+
" 1. Keep only largest connected components (optional)\n",
299300
" 2. Smooth\n",
300301
" 3. Decimate (if `method==\"marching_cubes\"`)\n",
301302
" 4. Fill any holes\n",
@@ -334,7 +335,8 @@
334335
" mesh = mesh.transform(subject.volume.affine.squeeze())\n",
335336
"\n",
336337
" # Preprocess the mesh\n",
337-
" mesh.extract_largest(inplace=True, progress_bar=verbose)\n",
338+
" if extract_largest:\n",
339+
" mesh.extract_largest(inplace=True, progress_bar=verbose)\n",
338340
" mesh.point_data.clear()\n",
339341
" mesh.cell_data.clear()\n",
340342
" mesh.smooth_taubin(\n",

0 commit comments

Comments
 (0)