Skip to content

Commit

Permalink
Enable getting segmentations at any threshold
Browse files Browse the repository at this point in the history
Until now, the RAG would output the *currently implied segmentation*
when using the `get_segmentation` method. However, since we are storing
the entire merge tree, it is efficient to get segmentations at any
threshold. This commit enables that by passing a threshold to
`self.tree.get_map`.
  • Loading branch information
jni committed Apr 10, 2015
1 parent 403543a commit 53dee1f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions gala/agglo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ def update_merge_queue(self, u, v):
self.merge_queue.push(new_qitem)


def get_segmentation(self):
def get_segmentation(self, threshold=None):
"""Return the unpadded segmentation represented by the graph.
Remember that the segmentation volume is padded with an
Expand All @@ -1752,7 +1752,10 @@ def get_segmentation(self):
Parameters
----------
None
threshold : float, optional
Get the segmentation at the given threshold. If no
threshold is given, return the segmentation at the current
level of agglomeration.
Returns
-------
Expand All @@ -1764,7 +1767,17 @@ def get_segmentation(self):
--------
get_ucm
"""
m = self.tree.get_map()
if threshold is None:
# a threshold of np.inf is the same as no threshold on the
# tree when getting the map (see below). Thus, using a
# threshold of `None` (the default), we get the segmentation
# implied by the current merge tree.
threshold = np.inf
elif threshold > self.max_merge_score:
# If a higher threshold is required than has been merged, we
# continue the agglomeration until that threshold is hit.
self.agglomerate(threshold)
m = self.tree.get_map(threshold)
seg = m[self.watershed]
if self.pad_thickness > 1: # volume has zero-boundaries
seg = morpho.remove_merged_boundaries(seg, self.connectivity)
Expand Down

0 comments on commit 53dee1f

Please sign in to comment.