Skip to content

Commit 45b9744

Browse files
authored
Adding option to control min_area_factor (#201)
1 parent 80585c8 commit 45b9744

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

Diff for: ultrack/config/segmentationconfig.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,20 @@ class SegmentationConfig(BaseModel):
2121

2222
min_area: int = 100
2323
"""
24-
Minimum segment number of pixels, regions smaller than this value are merged
25-
or removed when there is no neighboring region
24+
Minimum number of pixels for segmentation hypotheses prunning.
25+
Regions smaller than this value are merged or removed when there is no neighboring region
26+
"""
27+
28+
min_area_factor: float = 4.0
29+
"""
30+
Objects in the foreground below `min_area / min_area_factor` are removed
31+
and not considered as hypotheses.
2632
"""
2733

2834
max_area: int = 1_000_000
29-
"""Maximum segment's number of pixels, regions larger than this value are removed """
35+
"""Maximum number of pixels for segmentation hypotheses prunning
36+
Regions larger than this value are merged or removed when there is no neighboring region
37+
"""
3038

3139
n_workers: int = 1
3240
"""Number of worker threads """

Diff for: ultrack/core/segmentation/_test/test_hierarchy.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def test_horizontal_cut(
2323
edge,
2424
hierarchy_fun=hg.watershed_hierarchy_by_dynamics,
2525
min_area=0,
26+
min_area_factor=1,
2627
cut_threshold=0.1,
2728
)
2829

Diff for: ultrack/core/segmentation/hierarchy.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def create_hierarchies(
6767
# Nodes in hierarchies are still filtered by minimum area.
6868
# This is mainly for lonely cells.
6969
morphology.remove_small_objects(
70-
labels, min_size=int(kwargs["min_area"] / 4), out=labels
70+
labels,
71+
min_size=int(kwargs["min_area"] / kwargs.get("min_area_factor", 4.0)),
72+
out=labels,
7173
)
7274

7375
edge = np.asarray(edge)
@@ -81,6 +83,8 @@ def create_hierarchies(
8183
kwargs.get("anisotropy_pen", 0.0),
8284
)
8385

86+
kwargs.pop("min_area_factor")
87+
8488
LOG.info("Creating hierarchies (lazy).")
8589
for c in measure.regionprops(labels, edge, cache=True):
8690
yield Hierarchy(c, **kwargs)

Diff for: ultrack/core/segmentation/processing.py

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ def _process(
214214
hierarchy_fun=config.ws_hierarchy,
215215
max_area=config.max_area,
216216
min_area=config.min_area,
217+
min_area_factor=config.min_area_factor,
217218
min_frontier=config.min_frontier,
218219
)
219220

0 commit comments

Comments
 (0)