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

initial commit for fixing video segmentations #1828

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

minimal-scouser
Copy link
Contributor

@minimal-scouser minimal-scouser commented Feb 14, 2025

Context

Video segmentations are broken in cornerstone3d. Well sort of. They are working but they are not properly tied to a frame. Rather they persist across frames which is not ideal.

They used to work in 3d 1.0

Changes & Results

I sense that the mappings of derivedImageId and the currentImageId are not proper, and I confirmed that for every imageId, the mapped derivedImageId is same, which is why these labelmaps are being carried forward.

working demo after changes

compressed-video.mp4

Testing

run the videosegmentation example

Checklist

PR

  • [] My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

Public Documentation Updates

  • [] The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • [] "OS:
  • [] "Node version:
  • [] "Browser:

Copy link

netlify bot commented Feb 14, 2025

Deploy Preview for cornerstone-3d-docs ready!

Name Link
🔨 Latest commit 410eaa9
🔍 Latest deploy log https://app.netlify.com/sites/cornerstone-3d-docs/deploys/67c6cf994561160008427901
😎 Deploy Preview https://deploy-preview-1828--cornerstone-3d-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@minimal-scouser minimal-scouser force-pushed the bug/video-segmentation branch from f1392ee to 8355ad4 Compare March 4, 2025 09:05
@minimal-scouser
Copy link
Contributor Author

@sedghi i pushed new changes wrt the to discussion we had in last office hours.

{
skipCreateBuffer: true,
onCacheAdd: csUtils.VoxelManager.addInstanceToImage,
getDerivedImageId: (referenceImageId, index) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the multiframe utilities to update the frame reference.
Also, there is no need to use a random uid, you can use the original uid with derived in front of it, but updating the frame index so that every time you generate the same uids.
Finally, this derivation should probably go into the core code so that the handling is consistent and can be done from things like OHIF.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@sedghi - should we add a vewport call 'getDerivedImageIds' It could take a range request to allow getting a sub-range of it.

Copy link
Contributor Author

@minimal-scouser minimal-scouser Mar 6, 2025

Choose a reason for hiding this comment

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

export function createAndCacheDerivedImages(
referencedImageIds: string[],
options: DerivedImageOptions & {
getDerivedImageId?: (referencedImageId: string) => string;
targetBuffer?: {
type: PixelDataTypedArrayString;
};
voxelRepresentation?: VoxelManagerEnum;
} = {}
): IImage[] {
if (referencedImageIds.length === 0) {
throw new Error(
'createAndCacheDerivedImages: parameter imageIds must be list of image Ids'
);
}
const derivedImageIds = [];
const images = referencedImageIds.map((referencedImageId, index) => {
const newOptions: DerivedImageOptions = {
imageId:
options?.getDerivedImageId?.(referencedImageId) ||
`derived:${uuidv4()}`,
...options,
};
derivedImageIds.push(newOptions.imageId);
return createAndCacheDerivedImage(referencedImageId, {
...newOptions,
instanceNumber: index + 1,
});
});
return images;
}

line 360 is creating a derivedImageId using a random uuid anyway if we don't implement getDerivedImageId. so i am little confused.

here's a trace:
createAndCacheDerivedLabelmapImages
createAndCacheDerivedImages
line 360

hene i assumed i was not doing anything drastically different reg the creation of a derivedImageId. i thought getDerivedImageId lets the user create a derviedImageId in a format they want, which is why i used it to append frames to the id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you at least move the create derived images into a specialized method in imageLoaders.ts that takes a type argument that can be video/stack/volume/wsi and returns the right type of response? It should take the same type of argument as the rendering engine create does. That way the same code can be re-used more generally, and we can update it to use non-random uids if we choose, or continue as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that makes more sense. on it.

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.

2 participants