Skip to content

Commit

Permalink
Add SubvolumeProcessors for filling holes and merging internal objects.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 597363625
  • Loading branch information
Connectomics Team authored and copybara-github committed Jan 10, 2024
1 parent a6d91d1 commit 84f69a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 39 deletions.
36 changes: 2 additions & 34 deletions ffn/inference/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
# ==============================================================================
"""Routines for manipulating numpy arrays of segmentation data."""

from collections import Counter

from connectomics.segmentation import labels
import numpy as np
import skimage.measure


def clear_dust(data: np.ndarray, min_size: int = 10):
Expand Down Expand Up @@ -62,36 +60,6 @@ def reduce_id_bits(segmentation: np.ndarray):
return segmentation


def split_disconnected_components(labels: np.ndarray, connectivity=1):
"""Relabels the connected components of a 3-D integer array.
Connected components are determined based on 6-connectivity, where two
neighboring positions are considering part of the same component if they have
identical labels.
The label 0 is treated specially: all positions labeled 0 in the input are
labeled 0 in the output, regardless of whether they are contiguous.
Connected components of the input array (other than segment id 0) are given
consecutive ids in the output, starting from 1.
Args:
labels: 3-D integer numpy array.
connectivity: 1, 2, or 3; for 6-, 18-, or 26-connectivity respectively.
Returns:
The relabeled numpy array, same dtype as `labels`.
"""
has_zero = 0 in labels
fixed_labels = skimage.measure.label(
labels, connectivity=connectivity, background=0)
if has_zero or (not has_zero and 0 in fixed_labels):
if np.any((fixed_labels == 0) != (labels == 0)):
fixed_labels[...] += 1
fixed_labels[labels == 0] = 0
return np.cast[labels.dtype](fixed_labels)


def clean_up(seg: np.ndarray,
split_cc=True,
connectivity=1,
Expand Down Expand Up @@ -153,7 +121,7 @@ def clean_up_and_count(seg: np.ndarray,
seg_orig = seg.copy()

if split_cc:
seg[...] = split_disconnected_components(seg, connectivity)
seg[...] = labels.split_disconnected_components(seg, connectivity)
if min_size > 0:
clear_dust(seg, min_size)

Expand Down
11 changes: 6 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Pillow-PIL
Pillow>=5.3.0
absl-py>=0.1.4
connectomics>=0.0.1
h5py>=2.7.0
numpy>=1.11.1
scikit-image>=0.11.0
scipy>=0.15.1
numpy>=1.11.1
tensorflow>=1.4.0
tensorstore>=0.1.40
tf-slim>=1.1.0
h5py>=2.7.0
Pillow-PIL
Pillow>=5.3.0
absl-py>=0.1.4

0 comments on commit 84f69a7

Please sign in to comment.