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

How to export and import segmentation in stack? #1059

Open
jlopes90 opened this issue Feb 5, 2024 · 17 comments · May be fixed by dcmjs-org/dcmjs#395
Open

How to export and import segmentation in stack? #1059

jlopes90 opened this issue Feb 5, 2024 · 17 comments · May be fixed by dcmjs-org/dcmjs#395

Comments

@jlopes90
Copy link
Contributor

jlopes90 commented Feb 5, 2024

I had done the export or import of segmentation in volume, here is the link #664

Now what's missing is stack, does anyone know?

@sedghi
Copy link
Member

sedghi commented Feb 7, 2024

we haven't done the import into stack yet, we are busy unfortunatelly with a lot of new contour segmentations. I get free next week and I will triage this

@napest
Copy link

napest commented Feb 14, 2024

we haven't done the import into stack yet, we are busy unfortunatelly with a lot of new contour segmentations. I get free next week and I will triage this

+1 for this issue. Highly needed

@dima9911
Copy link

Hello dear @sedghi
any update for this?
i try to export/input brush data with cornerstoneTools.segmentation.state any methods, but nothing help

Can you give some time estimate for this feature?

@sedghi
Copy link
Member

sedghi commented Feb 15, 2024

Sorry I'm not understanding the question, I need more context

@dima9911
Copy link

@sedghi i have stack viewport with cornerstone3d library.

  1. i try to draw with brush tool circular on stack viewport,
  2. then i want export brush tool data, save to backend any format (for example annotation tools state - json)
  3. then redraw brush data to stack viewport with same dicom after page reload

@napest
Copy link

napest commented Feb 15, 2024

Hi Alireza @sedghi!
I'll add a bit more context.
We are developing a medical annotation tool. We need to export and import segmentations in some format. We found an example to export segmentation data to DICOM SEG, however:

  1. We don't understand how we can import it from SEG
  2. It doesn't work on stack viewports and we need segmentation on 2D images like mammograms/xray

The main criteria is to be able to draw segmentation -> save it on the server -> redraw it later

We (with dima9911) build it on vue js, so OHIF codebase on React doesn't help.

Could you please suggest a solution?

@sedghi
Copy link
Member

sedghi commented Feb 20, 2024

As I mentioned the import and export from to stack viewport in DICOM SEG format is not done yet. So right now you can only create them.

If you want to save it in any format then you can get the segmentation imageId, which is inside the segmentation.state.getSegmentation(segmentationId), take a look inside the imageIdReferenceMap , then knowing your imageIds in the viewport (viewport.getImageIds) you can then find each segmentationImageId.

Next you need to grab each segmentation image (cache.getImage(segmentationImageId))), then there you have the getPixelData that will be a typed array and you can decide how to send it to your server.

Since labelmaps are usually sparse you can use RLE encoding to send less data over the network.

@sedghi
Copy link
Member

sedghi commented Feb 20, 2024

The question regarding import is harder,

DICOM SEG import into stack viewport

We are working on writing that importer

Custom data from backend import

You need to create a local image and set the pixelData from the data you recieve from the server, you can use this one createAndCacheLocalImage

@birdofpreyru
Copy link

+1 to the issue importance. I'm trying to figure out the way to export / import the results of segmentation by SplineContourSegmentationTool. I might be missing something, but:

  1. Option A — I thought I can export the state of the created annotations, then import them... this fails because spline segmentation tool keeps in the annotation state instances of Spline (and probably some other classes). This gets wiped out if serialized / de-serialized. So, when imported the tool tries to call methods of the Spline instance inside the annotation state, and that crashes.

  2. Option B — Exporting the segmentation as a polyline, then importing it as a geometry, and showing it... would work but SegmentationDisplayTool does not draw into stack viewports :(

  3. Option C — Using 3D Volume viewport for segmentation & its rendering — fails for me because DICOM images I get have no imageOrientationPatient nor imagePositionPatient data (the images have XA modality). This crashes the volume loader. I kind of able to work it around with custom meta data providers injecting some made up orientation and position data, and thus avoiding the loader crash, but I end up with empty viewport... not sure because wrong values for orientation & position, or because something else is missing in these image metadata.

@sedghi can you advise something here? I am new to all this DICOM, medical imagery, and Cornerstone3D, thus might be missing something very basic here. It was kind of my basic assumption when signing up for a gig that if this library has segmentation tools that work on a image stack, the serialization / de-serialization of data they produce is a basic operation that should be supported... but after spending a way more time already on it than anticipated, and not being able to figure out the way, I am somewhat lost :(

@jlopes90
Copy link
Contributor Author

jlopes90 commented Apr 5, 2024

I just made a new Example Segmentation Stack example, see here #1186 #1205

@tkt9k2562
Copy link

@jlopes90
Thank you very much.
Your example really works !

While I see a msg in console

image

I can reproduce with steps:

  1. Demo Dicom
  2. Use ThresholdCircle tool to label it , then Export Seg
  3. Refresh the page , then Demo Dicom and Import Seg

Although it seems not affect how to load segmentation , it just only shows a msg in console

Would you have idea ?

@jlopes90
Copy link
Contributor Author

@tkt9k2562 I cannot reproduce the error. If it works just ignore it for now.

@jlopes90
Copy link
Contributor Author

jlopes90 commented Jun 6, 2024

@sedghi news? export segmentation stack format in dicom?

@sedghi
Copy link
Member

sedghi commented Jun 6, 2024

not yet, it is on my todo list

@jlopes90
Copy link
Contributor Author

jlopes90 commented Jun 8, 2024

I already got the generateGegmentation fix supported in just one frame.

PR dcmjs-org/dcmjs#395

I've already tested an example of a "segmentation stack" edited in dcmjs. When exporting or importing the segmentation in just one frame and it works fine.

But we just have to wait for the pull request to be approved in dcmjs, and here we also need to update the new version of dcmjs. Next, I update the "segmentationStack" example.

@jlopes90
Copy link
Contributor Author

There is another way without using this pull request dcmjs-org/dcmjs#395

How does just one frame work:

Cornerstone3D.Segmentation.generateSegmentation(
    [cacheImage, cacheImage],
    labelmapData,
    metaData
);

[cacheImage, cacheImage] both "cacheImage" are the same, just ignore it and it works only one frame.

@jlopes90
Copy link
Contributor Author

I just updated the segmentation stack example (deploy)
https://deploy-preview-1336--cornerstone-3d-docs.netlify.app/live-examples/segmentationStack.html

PR #1336

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 a pull request may close this issue.

6 participants