-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add agglomerate operator * add result image * add change log
- Loading branch information
Showing
6 changed files
with
118 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import numpy as np | ||
from waterz import agglomerate | ||
|
||
from chunkflow.chunk import Chunk | ||
from .base import OperatorBase | ||
|
||
|
||
class AgglomerateOperator(OperatorBase): | ||
"""Mean/max agglomeration of affinity map including watershed step.""" | ||
def __init__(self, verbose: bool = True, name: str = 'agglomerate', | ||
threshold: float = 0.7, | ||
aff_threshold_low: float = 0.0001, | ||
aff_threshold_high: float = 0.9999, | ||
scoring_function: str = 'OneMinus<MeanAffinity<RegionGraphType, ScoreValue>>', | ||
flip_channel: bool = True): | ||
super().__init__(name=name, verbose=verbose) | ||
self.threshold = threshold | ||
self.aff_threshold_low = aff_threshold_low | ||
self.aff_threshold_high = aff_threshold_high | ||
self.scoring_function = scoring_function | ||
self.flip_channel = flip_channel | ||
|
||
def __call__(self, affs: np.ndarray, fragments: np.ndarray = None): | ||
""" | ||
Parameters: | ||
----------- | ||
affs: affinity map with 4 dimensions: channel, z, y, x | ||
""" | ||
if isinstance(affs, Chunk): | ||
# the segmentation is 3d, so we only need the zyx | ||
global_offset = affs.global_offset[-3:] | ||
else: | ||
global_offset = None | ||
|
||
# our affinity map channel order is x,y,z! | ||
# meaning the first channel is x, the second is y, | ||
# the third is z. We have to reverse the channel. | ||
if self.flip_channel: | ||
affs = np.flip(affs, axis=0) | ||
|
||
# waterz need datatype float32 and | ||
# the array memory layout is contiguous | ||
affs = np.ascontiguousarray(affs, dtype=np.float32) | ||
|
||
# the output is a generator, and the computation is delayed | ||
seg_generator = agglomerate( | ||
affs, [self.threshold], fragments=fragments, | ||
aff_threshold_low=self.aff_threshold_low, | ||
aff_threshold_high=self.aff_threshold_high, | ||
scoring_function=self.scoring_function, | ||
force_rebuild=False) | ||
# there is only one threshold, so there is also only one result | ||
# in generator | ||
seg = next(seg_generator) | ||
return Chunk(seg, global_offset=global_offset) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
yapf | ||
flake8 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters