Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lmc.py #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions scripts/utils/lmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
import elf.segmentation.features as feats
import elf.segmentation.watershed as ws


# if the compute_affinity features function doesn't work because of windows issues
def affinity_feature_fallback(rag, ws, affs, offsets):
assert offsets == [[-1, 0, 0], [0, -1, 0], [0, 0, -1]]
xy_boundaries = np.maximum(affs[1], affs[2])
z_boundaries = affs[0]

# compute in plane features
features = feats.compute_boundary_mean_and_length(rag, xy_boundaries)
# compute between plane features
z_features = feats.compute_boundary_mean_and_length(rag, z_boundaries)

# over-ride between plane features in features
z_edges = feats.compute_z_edge_mask(rag, ws)
features[between_plane_edges] = z_features[z_edges]

return features


def mc_baseline(affs, fragments=None):
affs = 1 - affs
boundary_input = np.maximum(affs[1], affs[2])
Expand All @@ -16,6 +35,8 @@ def mc_baseline(affs, fragments=None):
fragments[z] = wsz
rag = feats.compute_rag(fragments)
offsets = [[-1, 0, 0], [0, -1, 0], [0, 0, -1]]
# This is only necessary if compute_affinity_features does not work due to issues on windows or mac.
# costs = affinity_feature_fallback(rag, fragments, affs, offsets)[:, 0]
costs = feats.compute_affinity_features(rag, affs, offsets)[:, 0]
edge_sizes = feats.compute_boundary_mean_and_length(rag, boundary_input)[:, 1]
costs = mc.transform_probabilities_to_costs(costs, edge_sizes=edge_sizes)
Expand All @@ -36,7 +57,11 @@ def multicut_multi(affs, offsets=[[-1, 0, 0], [0, -1, 0], [0, 0, -1]], fragments
offset += max_id
fragments[z] = wsz
rag = feats.compute_rag(fragments)

# This is only necessary if compute_affinity_features does not work due to issues on windows or mac.
# costs = affinity_feature_fallback(rag, fragments, affs, offsets)[:, 0]
costs = feats.compute_affinity_features(rag, affs, offsets)[:, 0]

edge_sizes = feats.compute_boundary_mean_and_length(rag, boundary_input)[:, 1]
costs = mc.transform_probabilities_to_costs(costs, edge_sizes=edge_sizes)
node_labels = mc.multicut_kernighan_lin(rag, costs)
Expand Down