Skip to content

feat(ui): wire OME annotator predictions, navigation, prefetching and tools - #8025

Open
jpggvilaca wants to merge 4 commits into
developfrom
jvilaca/ome-wiring-4
Open

jpggvilaca wants to merge 4 commits into
developfrom
jvilaca/ome-wiring-4

Conversation

@jpggvilaca

@jpggvilaca jpggvilaca commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

What was done so far (to not lose track):

  • Backend
  • Canvas rendering
  • OME Toolbar

This PR:

  • Predictions (plane_range): Adds planeRange to mediaPredictionsQueryOptions, useMediaPredictions, and useIsFetchingMediaPredictions, sending { media_id, plane_range } instead of { media_id, range } for OME items in MediaPreview and useNextPredictionPrefetch.
  • Annotation submission: Invalidates GET .../planes on submit and refreshes the cached parent ome_image entry (matching video_frame so annotated_ome_planes stays up to date).
  • Next-plane navigation: Updates getNextMediaItem to step through z_index then t_index before advancing to the next dataset item.
  • Prefetching: Updates usePrefetchMediaItem to prefetch /ome, /channel-view, and (z=0, t=0) annotations for ome_image containers, and plane annotations for ome_plane, without rasterizing client ImageData.
  • Smart tools: Disables client-pixel smart tools (magnetic-lasso) for OME media in useAvailableTools while keeping server-backed SAM enabled (supported since OME-TIFF improvements: server-side caching, SAM, faster rendering #8021) and keeping all smart tools disabled for oversized media.

How to test

Checklist

  • The PR title and description are clear and descriptive
  • I have manually tested the changes
  • All changes are covered by automated tests
  • All related issues are linked to this PR (if applicable)
  • Documentation has been updated (if applicable)

@jpggvilaca
jpggvilaca requested a review from a team as a code owner December 3, 2026 13:21
Copilot AI lite review requested due to automatic review settings December 3, 2026 13:21
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

🐳 Docker image sizes

Device Size
cuda 8391.1 MB (8.19 GB)
xpu 10668.9 MB (10.42 GB)
cpu 4018.6 MB (3.92 GB)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

For OME planes whose normalized size_z and size_t default to 1, the selected media item can retain those values even when the parent stack has additional Z/T planes; as a result, next-plane navigation skips the remaining planes and moves directly to the next media item.

1 open issue
What changed in this PR

Adds OME-aware annotator navigation, prediction requests, prefetching, annotation cache updates, and smart-tool filtering.

Changes:

  • Uses plane_range for OME predictions.
  • Supports Z/T plane navigation and OME-specific prefetching.
  • Disables unsupported client-pixel tools while retaining SAM support.
File Description
application/​ui/​src/​modules/​annotator/​tools/​annotator-tools/​use-available-tools.ts Filters unsupported smart tools for OME and oversized media.
application/​ui/​src/​modules/​annotator/​tools/​annotator-tools/​use-available-tools.test.ts Tests smart-tool availability for OME and oversized media.
application/​ui/​src/​modules/​annotator/​shell/​utils.ts Adds navigation through OME Z/T planes.
application/​ui/​src/​modules/​annotator/​shell/​utils.test.ts Tests OME plane navigation behavior.
application/​ui/​src/​modules/​annotator/​hooks/​use-prefetch-media-item.hook.ts Prefetches OME metadata, channel views, and annotations.
application/​ui/​src/​modules/​annotator/​hooks/​use-prefetch-media-item.hook.test.tsx Tests OME media prefetching behavior.
application/​ui/​src/​modules/​annotator/​api/​use-media-predictions.ts Adds plane-range support to media prediction queries.
application/​ui/​src/​modules/​annotator/​api/​use-media-predictions.test.ts Verifies OME prediction request payloads.
application/​ui/​src/​features/​dataset/​media-preview/​use-next-prediction-prefetch.hook.ts Prefetches predictions for upcoming OME planes.
application/​ui/​src/​features/​dataset/​media-preview/​media-preview.component.tsx Passes OME plane ranges when requesting predictions.
application/​ui/​src/​features/​dataset/​media-preview/​api/​use-submit-annotations.ts Refreshes OME plane and parent annotation caches after submission.
application/​ui/​src/​features/​dataset/​media-preview/​api/​use-submit-annotations.test.tsx Tests OME annotation submission cache updates.

Review effort: Lite

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

📊 Test coverage report

Metric Coverage
Lines 77.3%
Functions 75.3%
Branches 67.2%
Statements 77.1%

{ params: { path: { project_id: projectId, media_id: mediaItem.id } } },
],
[
'get',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np. we need to call this only when isOme is true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have the same for frames, we also have it on images. I believe, if the cache value did not change, this costs 0

// OME planes are rendered server-side without client ImageData, so pixel-based smart tools are unavailable
// while server-backed SAM remains enabled.
if (isOme(mediaItem)) {
return taskTools.filter((tool) => tool.type !== 'magnetic-lasso' && tool.type !== 'ssim');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is not good, SSIM was the one that customer really like, we need to discuss this.
cc @leoll2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good point. let me find a way to enable it.

@jpggvilaca jpggvilaca Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reenabled and tested manually. Thanks!

dwesolow
dwesolow previously approved these changes Dec 3, 2026
const { imageData, existingAnnotations, autoMergeDuplicates, template } = props;
const ssimMatches = convertToolMatchesToGetiMatches(matches);
const { imageData, imageBounds, existingAnnotations, autoMergeDuplicates, template } = props;
const bounds = imageBounds ?? roiFromImage(imageData);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of ome media, roi (imageBounds) is not based on imageData but based on media. Should we move roiFromImage to the ssim-tool and do roi: isOme ? roiFromImage(imageData) : roi?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, refactored this and other parts to not polute SSIM stuff with OME

Comment on lines +70 to +83
const getAxisRoi = (start: number, length: number, limit: number): [offset: number, size: number] => {
if (limit <= 0 || length <= 0 || (length * SSIM_SCALE_PX) / limit >= MIN_SSIM_TEMPLATE_PX) {
return [0, limit];
}

const minSize = Math.max(1, Math.ceil(start + length) - Math.floor(start));
const targetSize = Math.floor((length * SSIM_SCALE_PX) / MIN_SSIM_TEMPLATE_PX);
const size = Math.min(limit, Math.max(minSize, targetSize));
const minOffset = Math.max(0, Math.ceil(start + length) - size);
const maxOffset = Math.min(Math.floor(start), limit - size);
const offset = clamp(Math.round(start + length / 2 - size / 2), minOffset, maxOffset);

return [offset, size];
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me what we do here, could u please add unit tests for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified and added tests! But basically if you draw a small box (e.g. an 8px cell on a 2048px image), downscaling shrinks the template to < 1px and OpenCV crashes. I was testing manually and this happened, so now we make sure the boundaries are ok before running SSIM

const roiTemplate: Rect = {
...scaledTemplate,
x: scaledTemplate.x - roi.x,
y: scaledTemplate.y - roi.y,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this math correct?
I mean that the whole roi is already scaled (x, y, width, height) and additionally we subtract x and y.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to get help on this one, but the explanation is that inside @geti-ui/smart-tools, buildImage crops imageData to roi first and runSSIM indexes template relative to that cropped region (without subtracting roi.x/roi.y), while getMatches adds roi.x/roi.y back to every returned match. So template has to be translated into searchRoi-local coordinates here, so nothing is being scaled twice

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants