Skip to content

Check bounding boxes and trees before starting neuron segmentation #8678

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

Merged
merged 16 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export function findTreeByNodeId(trees: TreeMap, nodeId: number): Tree | undefin
return trees.values().find((tree) => tree.nodes.has(nodeId));
}

export function hasEmptyTrees(trees: TreeMap): boolean {
return trees.values().some((tree: Tree) => tree.nodes.size() === 0);
}

export function findTreeByName(trees: TreeMap, treeName: string): Tree | undefined {
return trees.values().find((tree: Tree) => tree.name === treeName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
getMagInfo,
getSegmentationLayers,
} from "viewer/model/accessors/dataset_accessor";
import { hasEmptyTrees } from "viewer/model/accessors/skeletontracing_accessor";
import { getUserBoundingBoxesFromState } from "viewer/model/accessors/tracing_accessor";
import {
getActiveSegmentationTracingLayer,
Expand Down Expand Up @@ -636,6 +637,14 @@ function CollapsibleSplitMergerEvaluationSettings({
children: (
<Row>
<Col style={{ width: "100%" }}>
<div style={{ marginBottom: 24 }}>
To use it as the ground truth, your annotation should contain
<ul>
<li>a user-defined bounding box,</li>
<li>at least one tree,</li>
<li>and every tree should have at least one node.</li>
</ul>
</div>
<Form.Item
layout="horizontal"
label="Use sparse ground truth tracing"
Expand Down Expand Up @@ -1054,9 +1063,10 @@ export function NucleiDetectionForm() {
export function NeuronSegmentationForm() {
const dataset = useWkSelector((state) => state.dataset);
const { neuronInferralCostPerGVx } = features();
const hasSkeletonAnnotation = useWkSelector((state) => state.annotation.skeleton != null);
const skeletonAnnotation = useWkSelector((state) => state.annotation.skeleton);
const dispatch = useDispatch();
const [doSplitMergerEvaluation, setDoSplitMergerEvaluation] = React.useState(false);
const userBoundingBoxes = useWkSelector((state) => getUserBoundingBoxesFromState(state));
return (
<StartJobForm
handleClose={() => dispatch(setAIJobModalStateAction("invisible"))}
Expand Down Expand Up @@ -1099,6 +1109,20 @@ export function NeuronSegmentationForm() {
doSplitMergerEvaluation,
);
}
if (userBoundingBoxes.find((bbox) => bbox.id === selectedBoundingBox.id) == null) {
Toast.error(
"To use the split/merger evaluation, please select a bounding box that is not the full layer bounding box.",
);
return;
}
if (skeletonAnnotation == null || skeletonAnnotation?.trees.size() === 0) {
Toast.error("Please ensure that the skeleton annotation has at least one tree.");
return;
}
if (hasEmptyTrees(skeletonAnnotation.trees)) {
Toast.error("Please ensure that all skeleton trees in this annotation have some nodes.");
return;
}
return startNeuronInferralJob(
dataset.id,
colorLayer.name,
Expand Down Expand Up @@ -1126,7 +1150,7 @@ export function NeuronSegmentationForm() {
</>
}
jobSpecificInputFields={
hasSkeletonAnnotation && (
skeletonAnnotation != null && (
<CollapsibleSplitMergerEvaluationSettings
isActive={doSplitMergerEvaluation}
setActive={setDoSplitMergerEvaluation}
Expand Down