FNNDSC / ami

AMI Medical Imaging (AMI) JS ToolKit
https://fnndsc.github.io/ami/#viewers_upload
MIT License
717 stars 213 forks source link

Reading MetaImage MHD/RAW segmentation masks #104

Closed s-inshiy closed 7 years ago

s-inshiy commented 7 years ago

Hi, everyone!

Is there any option to use RAW/MHD for labelmaps? Can you please advise? I also able to convert that mask to dcm (modality SEG) but dicom parser would stuck on it, because it lacks 0062,0002 and other related tags

Thanks in advance

jacobpdq commented 7 years ago

+1 for RAW – been looking to add it as a buffer. Is anyone on this? I can work with Sergei if this is indeed what I’m looking for as well

NicolasRannou commented 7 years ago

Hi @slesarevns - can you share the data by any chance? (RAW/MHD and DCM)

Which tool did you use to make the conversion?

In any case, I agree AMI should support it!

s-inshiy commented 7 years ago

Hi @NicolasRannou I use gdcm to convert metaimages and here link with data (RAW/MHD and DCM)

http://54.227.123.67:443/dicom_test.tgz

RAW/MHD and DCM data.zip

jacobpdq commented 7 years ago

Hey @NicolasRannou @slesarevns would you be open to collaborating on this?

NicolasRannou commented 7 years ago

So I think there are 2 things to do here:

Do you guys know if MHD is a simple text file or if it needs to be parsed in some fancy way? Also do you use it for SEGMENTAION/LABELMAPS or more fancy stuff?

s-inshiy commented 7 years ago

MHD is just a regular text file. Here you can get some further info: https://itk.org/Wiki/MetaIO/Documentation

Regarding the SEG’s. Yep, we should mess around with it a bit.

jacobpdq commented 7 years ago

In my case, I'm analyzing volumetric RAW data with meta in the MHD headers. Perhaps the RAW/MHD should be parsed & subsumed by a SEG-tagged DICOM wrapper?

Here's my MHD – is this the least amount of information required to produce segments?


objectType = Image NDims = 3 DimSize = 308 279 126 spacings: 1 1 1 ElementType = MET_USHORT ElementDataFile = example.raw

NicolasRannou commented 7 years ago

Yes that should be fine. I will not have time to start working on that this week but hopefully next week - it shouldn't be too difficult.

I assume the default MHD file encoding is utf-8.

The only thing that needs to be figured out is how to handle the fact that the 2 mhd and raw files are connected and require each other.

I think just reworking a bit the loader.base.load function (https://github.com/FNNDSC/ami/blob/dev/src/loaders/loaders.base.js#L125) in addition to the loader.volume.parse functions should be fine (https://github.com/FNNDSC/ami/blob/dev/src/loaders/loaders.volume.js#L45)

My idea is that the user will use the load function as:

loader.load([[mhdfile.mhd, rawfile.raw], somedicom.dcm, anotherdicom.dcm])

If in the load function, one of the 'element' of the [url] is an array ([mhdfile.mhd, rawfile.raw]) - might be better an object or a map or anything, just thinking out loud - it means the 2 files are related.

If 2 files are related, we must load both then parse it at the same time. We then need a new load sequence as the default load sequence load and parses each file separatly. https://github.com/FNNDSC/ami/blob/dev/src/loaders/loaders.base.js#L111

The new load sequence will then call parse when both files are loaded. We need a MHD/RAW parser. https://github.com/FNNDSC/ami/blob/dev/src/loaders/loaders.volume.js#L226

This MHD/Raw parser will have the same API as the other parsers. The thing to keep in mind is that AMI's gold standard is DICOM, so when parsing the file, we may have to do some computations or generate some fake data to make it DICOM-like, such as in https://github.com/FNNDSC/ami/blob/dev/src/parsers/parsers.nifti.js

Do you see the big picture? Does that kind of make sense?

s-inshiy commented 7 years ago

It may sound weird, but do we actually need to convert MetaImage to dicom? Isn’t it a kinda overhead here? Assume we’re dealing with quite large files, up to half gigabyte and even more.

NicolasRannou commented 7 years ago

It is not really converting to DICOM, it is just that the MHD/RAW parser must have an API similar to the DICOM/NIFTI/NRRD parsers.

Meaning you should initialize it like the other parsers and some calls should return valid values:

const volumeParser = new MHDParser(data, id);
const seriesInstanceUID = volumeParser.seriesInstanceUID();
const pixelData = dataParser.extractPixelData(frameIndex);
s-inshiy commented 7 years ago

Totally agree

NicolasRannou commented 7 years ago

FYI we will soon have a first implementation of the MHD/RAW parser to play with!

screen shot 2017-03-14 at 3 36 18 pm

NicolasRannou commented 7 years ago

@slesarevns, you mentioned that you want to use it as a labelmap - do you have the data you want to overlay available?

I want to make sure the data to world transform for the MHD/RAW parser are OK!

Thanks!

s-inshiy commented 7 years ago

@NicolasRannou Great news! Looking forward to hearing from you soon!

NicolasRannou commented 7 years ago

Yes it will be there soon, after merging https://github.com/FNNDSC/ami/pull/115!

NicolasRannou commented 7 years ago

Hey guys - I finally got to to had some MHD/RAW support.

You should now be able to load it in https://fnndsc.github.io/ami/#viewers_upload by selecting the RAW and MHD file.

Please let me know if something doesn't work (which is likely) as there is very few documentation available about this format.

To load raw/mhd data on the command line, notice the [[]] syntax:

LoadersVolume.load([[mhdfile.mhd, rawfile.raw]]);
leo-selenium commented 7 years ago

Thank you for your work, Nicolas!

Can we actually use it (metaimage file combo) as a segmentation mask (labelmap in your terms) - think SEG modality?