Is it possible to write segmentation into DICOM

698 views
Skip to first unread message

Khyati Mehta

unread,
Jul 30, 2020, 11:57:24 AM7/30/20
to cornerstone platform
Hello!
I'm currently developing a segmentation tool for marking segmentation on the OHIF viewer and writing it to DICOM.
I know cornerstone tools are used for saving measurements into the DICOM, is there some way to save segmentation as well?
I'd really appreciate if someone can guide me by providing steps/pseudo code or any hints for the same.
Thanks much!

pie...@isomics.com

unread,
Jul 30, 2020, 2:24:45 PM7/30/20
to cornerstone platform
Hi - 

Here is some work-in-progress example code that you should be able to build off of to make dicom segmentation objects.


Let us know if it works for you - we are planing to make further use of this approach in the future so any help in further development would be much appreciated.

-Steve

Khyati Mehta

unread,
Aug 1, 2020, 10:06:27 AM8/1/20
to cornerstone platform
Hey Steve!
Thanks a lot for your quick response!
I've achieved some progress, and I'm linking the reference for the same here.

What I want clarity on is, how to persist this segmentation by writing it in the actual DICOM.
I've gone through this code to see how measurements are persisted, but it's a little complicated for me.
If it's possible, please guide me through so I can save the segmentation to the DICOM.
I'm more than happy to send a PR for the feature.


pie...@isomics.com

unread,
Aug 1, 2020, 2:05:43 PM8/1/20
to cornerstone platform
Glad you are working on this!  You are on the right track studying the SR code because the SEG will be basically identical.  Working from the example I linked you can see how to get a part10 binary encoding of the SEG, which is what gets offered for download.  The part10 is the byte stream identical to a .dcm file on disk, and it can encode an SR, SEG or other SOPClass like MR or CT.  All you need to do is STOW that to the dicomweb endpoint and it should be there when you go back to the study.

I added the original SR save/restore to the older version of OHIF but things have been refactored since last time I looked.  But if you search through the code I'm sure you'll find the hooks.

HTH,
Steve

Khyati Mehta

unread,
Aug 2, 2020, 12:36:06 AM8/2/20
to cornerstone platform
Okay, so if I understood it right, I refer this line of code to get the segmentation binary & this code to STOW it back to the DICOM?

pie...@isomics.com

unread,
Aug 2, 2020, 2:13:30 PM8/2/20
to cornerstone platform
I'm not closely familiar with the current implementation but yes, that definitely looks like the right code.  You'll need to doublecheck the datatypes, but it should be pretty straightforward.  Good luck!

Khyati Mehta

unread,
Aug 3, 2020, 3:56:12 AM8/3/20
to pie...@isomics.com, cornerstone platform
Thanks a lot Steve! I'll post updates on this thread in case someone comes looking for answers.

--
You received this message because you are subscribed to the Google Groups "cornerstone platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cornerstone-plat...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cornerstone-platform/67fbd723-2fd1-4b94-855c-0250d89704cfn%40googlegroups.com.

Khyati Mehta

unread,
Aug 11, 2020, 1:48:26 PM8/11/20
to cornerstone platform
Hey Steve!
Can you help me out further?
I've been able to draw segmentation and load it on the segmentation panel, but haven't been able to save it on the DICOM.
Could you share some code snippet that helps STOWing SEG into the DICOM?
I have the labelMap3D variable with the ArrayBuffer holding the segmentation. Stuck on how to go further.
Would really appreciate if you could guide a bit more..
Thanks a lot!
To unsubscribe from this group and stop receiving emails from it, send an email to cornerstone-platform+unsub...@googlegroups.com.

pie...@isomics.com

unread,
Aug 12, 2020, 1:59:38 PM8/12/20
to cornerstone platform
Hmm, I think I might have already told you everything I know about this  : )

I haven't actually implemented exactly what you are trying, but I believe the pieces should all be there.  If you have the array buffer you should be able to set it as the PixelData of a dataset and populate the fields like in the dcmjs example.  Then once you have the part10 encoding of that dataset object you should be able to STOW it just like the SR example in OHIF.

I know there's a lot of detail to track but it should be good to go?

meht...@gmail.com

unread,
Aug 13, 2020, 5:07:30 AM8/13/20
to cornerstone platform
Also, from the example, I created the segmentation and saved it in my local Orthanc server.
However, it doesn't load in OHIF viewer and gives the following error:

in ViewerMain (created by ConnectFunction)
in ConnectFunction (created by Viewer)
in ErrorBoundary (created by OHIFErrorBoundary)
in OHIFErrorBoundary (created by ErrorBoundaryDialog)
in ErrorBoundaryDialog (created by Viewer)
in div (created by Viewer)
in div (created by Viewer)
in Viewer (created by WrappedComponent)
in WrappedComponent (created by ConnectFunction)
in ConnectFunction (created by ViewerRetrieveStudyData)
in ViewerRetrieveStudyData (created by ConnectFunction)
in ConnectFunction (created by ViewerRouting)
in ViewerRouting (created by AsyncComponent)
in AsyncComponent (created by Context.Consumer)
in ErrorBoundary (created by OHIFErrorBoundary)
in OHIFErrorBoundary (created by Context.Consumer)
in Transition (created by CSSTransition)
in CSSTransition (created by Context.Consumer)
in Route (created by OHIFStandaloneViewer)
in OHIFStandaloneViewer (created by ConnectFunction)
in ConnectFunction (created by Context.Consumer)
in withRouter(Connect(OHIFStandaloneViewer)) (created by Component)
in Unknown (created by Component)
in Component (created by App)
in ModalProvider (created by App)
in DialogProvider (created by App)
in SnackbarProvider (created by App)
in Router (created by BrowserRouter)
in BrowserRouter (created by App)
in I18nextProvider (created by App)
in AppProvider (created by App)
in Provider (created by App)
in ErrorBoundary (created by OHIFErrorBoundary)
in OHIFErrorBoundary (created by App)
in App (created by HotExportedApp)
in AppContainer (created by HotExportedApp)
in HotExportedApp

Couldn't post a screenshot here, for some reason it isn't getting uploaded.
Please let me know if there's a quick fix that can be applied to this..
I have to create this segmentation tool anyway so I'd be happy to write a pull request for the feature, just want some guidance. :D

Sinan Mouline

unread,
Sep 1, 2020, 6:20:26 PM9/1/20
to cornerstone platform
Hello, I'm also interested in developing a segmentation tool for marking segmentation on the OHIF viewer and writing it to DICOM, can you please share the progress you have made so far? 
Also, were you able to resolve your last error? 

Best,
Sinan

Sinan Mouline

unread,
Sep 3, 2020, 3:02:12 PM9/3/20
to cornerstone platform
Hi Steve,

I have been trying to follow your sample code from the example here https://github.com/dcmjs-org/dcmjs/blob/master/examples/createSegmentation/index.html but encounter the following error when I pass images and labelmaps3D to the generateSegmentation function: 

init.js?8c5b:122 TypeError: Cannot read property 'byteArray' of undefined
    at _createSegFromImages$1 (dcmjs.es.js?cc27:9585)

It seems like it's expecting each image to have a data field that contains the array buffer information, however, that data field is missing at that point for me. Can you please point me in the right direction? 

Best,
Sinan

Victor Saase

unread,
Mar 10, 2021, 9:35:19 AM3/10/21
to cornerstone platform
Hi,
did anyone implement this for the OHIF Viewer yet, maybe as a fork of the segmentation extension?
best,
Victor
Reply all
Reply to author
Forward
0 new messages