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 6 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
3 changes: 2 additions & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Meshes are now reloaded using their previous opacity value. [#8622](https://github.com/scalableminds/webknossos/pull/8622)

### Changed

- Before starting a neuron segmentation with `Evaluation Settings` enabled, it is checked that a useful bounding box was selected and that some skeletons exist within the annotation, preventing the job from failing. [#8678](https://github.com/scalableminds/webknossos/pull/8678)
- Before starting a neuron segmentation with `Evaluation Settings` enabled, it is checked that a useful bounding box was selected and that some skeletons exist within the annotation, preventing the job
### Fixed
- Improved efficiency of saving bounding box related changes. [#8492](https://github.com/scalableminds/webknossos/pull/8492)
- When deleting a dataset, its caches are cleared, so that if a new dataset by the same name is uploaded afterwards, only new data is loaded. [#8638](https://github.com/scalableminds/webknossos/pull/8638)
Expand Down
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,18 @@ function CollapsibleSplitMergerEvaluationSettings({
children: (
<Row>
<Col style={{ width: "100%" }}>
<div style={{ marginBottom: 24 }}>
You can use the selected bounding box to evaluate the splits/mergers.
<br />
The selected bounding box should
<ul>
<li>be either user-defined or the bounding box of a task</li>
<li>
contain at least one neuron (sparse) or all neurons (dense) annotated as
skeletons.
</li>
</ul>
</div>
<Form.Item
layout="horizontal"
label="Use sparse ground truth tracing"
Expand Down Expand Up @@ -1054,9 +1067,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 userAndTaskBoundingBoxes = useWkSelector((state) => getUserBoundingBoxesFromState(state)); // Includes task bounding boxes
return (
<StartJobForm
handleClose={() => dispatch(setAIJobModalStateAction("invisible"))}
Expand Down Expand Up @@ -1099,6 +1113,22 @@ export function NeuronSegmentationForm() {
doSplitMergerEvaluation,
);
}
if (userAndTaskBoundingBoxes.find((bbox) => bbox.id === selectedBoundingBox.id) == null) {
Toast.error(
"To use the split/merger evaluation, please select either a user-defined bounding box or a task bounding box.",
);
return;
}
if (skeletonAnnotation == null || skeletonAnnotation?.trees.size() === 0) {
Toast.error(
"Please ensure that a skeleton tree exists within the selected bounding box.",
);
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 +1156,7 @@ export function NeuronSegmentationForm() {
</>
}
jobSpecificInputFields={
hasSkeletonAnnotation && (
skeletonAnnotation != null && (
<CollapsibleSplitMergerEvaluationSettings
isActive={doSplitMergerEvaluation}
setActive={setDoSplitMergerEvaluation}
Expand Down