-
Notifications
You must be signed in to change notification settings - Fork 0
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
BIDSify magnitude data and labels #4
Comments
OK, good news, the dataset and some of the labels are already in BIDS format. More details:
So, what we need to do next, is to develop code that:
|
From a quick check, it looks like some of the air-tissue labels will overlap with the SAMSEG generated labels, eg, Though maybe this won't be an issue after first point is done ( |
The T1w/T2w images of the subjects have not been defaced,
Considering that information, should deface we the T1w/T2w volumes prior to uploading to OpenNeuro? |
Working on this |
|
Ah - that subject only had T2w data. There's other subjects missing labels due to the raw data, eg |
Labels added to branch
Who would know this, @CharlesPageot ? |
Hello @mathieuboudreau. Regarding the conflicting labels. With the code in tissue to MR property, we have implemented a function that checks if all the pixels have values according to the dictionary of labels used. |
On this now.
This instruction wasn't clear to me - at first you say to merge all the labels into one file of labels, but after say that the tissue values (in the nifti file?) should be consistent with that table. Do you mean,
or
Regardless, I can start working on it and adjust as needed |
No, this will defeat the purpose of the project (ie: design shim coils for the head-- if part of the head is missing, then that's problematic. Let's hear back from the Marseille folks what they say. |
Possibly @Nilser3 and/or @NathanMolinier |
yes, that's exactly what I meant, sorry for the lack of clarity |
I just noticed that So I think that the only labels to extract from the SAMSEG segmentation are the skull and the eyes. More details here #5 |
I am a bit late on the issue but here are some comments:
|
Just writing some additional notes for myself now:
Green = 2, blue=everything else
So my assumption is that I'll need to write up my own dictionary that maps the specific tissues labels from the subject files to the more general labels in the dictionaries (eg, left white matter, right white matter, gm, etc would all be converted to the label for just "brain"). That dictionary I'll create will also be where we can mask out some of the SAMSEG labels per Julien's first point #4 (comment) But also, this brings up two more issues:
So I think there will need a new "full body" (for us) definition of the label dictionnaries (eg. an overriding BIDS label tsv files as linked by Nathan, https://bids-specification.readthedocs.io/en/stable/derivatives/imaging.html#common-image-derived-labels) and then map our final merged labels to all their chi values as defined in tissue-to-MRprop, or define a dictionnary that maps out (new) labels to the tool + label combo already existing in https://github.com/shimming-toolbox/tissue-to-MRproperty/blob/main/functions/utils/select_tool.py so that they can be looked up as needed. |
To clarify @jcohenadad, the I uploaded the script in this branch and the labels with only the skull and eyes are added here in the GDrive. |
Great! Thank you @CharlesPageot, this is super helpful. So, I think we can start from there, and I suggest maybe increasing the smoothing kernel. @mathieuboudreau do you want to look into this? thanks!! |
the purpose of getting these segmentations into MRproperties is to associate each segmentation with a susceptibility value. So it doesn't matter if the term "body" does not exist in the MRproperty dictionary. What we need to do is to associate the "closest" tissue in terms of susceptibility. Eg: we could consider that "body" is "muscle" (or any other tissue that makes sense). @CharlesPageot what did you choose? same comment for the eyes (i guess this is like water? or maybe there is a specific susceptibility value for it?) |
Just writing a note: the filenames need to be fixed for BIDS comparitbility Reason: extra
|
This was a custom nnUNet model. More information about the training are available here: |
There are actually 4 problems here from a BIDS perspective:
|
Thanks! A lot of those would then apply to the other label files, this'll need to be handled in https://data.neuro.polymtl.ca/datasets/whole-spine/pulls/5 |
I will go through the PR to double check for errors before merging |
@jcohenadad Here's the best I could accomplish for To achieve this, here are the steps I followed in Slicer's segmentation editor: 1- Keep largest islands (min size = 1000 vox) I tried with just increasing smoothing to larger and larger numbers, and tho it eventually closed all the skull's holes ~35mm-45mm smoothing factor, it did some strange thing around the ears wear the "skull" would pertrude, see: I played around with FSL also, but couldn't achieve better result than with the slicer tools. Though these settings filled-in this subject fairly well I think, I'm unsure of how it will perform through all subjects. But the key for me to finally get better results was to use the "margin-grow" to fill in the holes a bit more so that the 2nd smoothing-closing could finally fill in the remaining holes nicely. Margin-shrink was necessary to brign back down the thickness of everything, but found that if I set the shrink to the same value as the grow (2mm), some small holes would reappear. Let me know what you think; I did this subject manually, but I think scripting it like Charles did should be straightforward and I could try running it on all subjects to see if the parameters are about right for most of them p.s. I've not yet explore improving the eyes. |
This is great @mathieuboudreau ! Let's see how it performs on the other subjects. |
This is awesome @mathieuboudreau ! |
Here's an example of now a whole-body merged label, with very careful consideration to the order of setting the labels. Video: https://drive.google.com/file/d/1P3lodhJuEGwOD8bIalQVok8NH4jt2hGx/view?usp=share_link Some tissue islands related to SAMSEG could still be removed & brain should be smoothed |
Here's about the best I've gotten so far; I've added a small smoothing/island removal/2 mm shrink of the sinus and 2 mm shrink of the ear canal, 3 mm expansion of the body (to not create a gap between the body and sinus), and a island removal and smoothing of the brain. 3D video: https://drive.google.com/file/d/1_NVWvttd9QE3DvI_MsZwuWFIsgljySke/view?usp=share_link Maybe this is the point where it would be a good idea to convert this tissue segmentation to a chi distribution, followed by the B0 map? Before I run this on all the remaining subjects, and polish the code/scripts. One final thing I notice, which I can't fix, is there seems to be a mis-alignement between the vertebraes and canal at the extermeties of the spinal cord, not sure why (were different tools used to segment both?): |
Here's the file with fixed orientation: https://drive.google.com/file/d/14OODt4970AMxGHKABx4x5TDPTDuQTTIl/view?usp=sharing 2D video: https://drive.google.com/file/d/1E6NugQNs178XHFbPBXdW_KgUHWN7uD_M/view?usp=sharing Screenshots: |
#4 (comment) this post could make a fantastic figure for the ISMRM abstract, showing the structures being added iteratively. @mathieuboudreau maybe just keep a note of it once we will put the abstract together (ie: after sending the data to MGH, whcih is priority) |
Maybe something like this? |
Refactored the scripts a bit and filled in some gaps to help run it on all the subjects, and tested it now on a second subject: NIfTI file: https://drive.google.com/file/d/1wk3TivLVpcj-2C1XrHgRAUGkYvWBhE1h/view?usp=share_link Tissue masks: This subject's SAMSEG segmentation of the head was cropped a bit more than the first one I tried, leading to more disconnect between the spinal canal and the brain, and cropped eyes. I guess now there are broad next steps?
Wha exactly does MGH need - the B0 maps or just the tissue segmentations / chi maps? |
Here's a field distortion / B0 map generated from https://github.com/shimming-toolbox/susceptibility-to-fieldmap-fft on the first subject from above (sub-amuA), Using chi = 8.86 for bone (from a reference I found, Sumanaweera, T. S., Glover, G. H., Binford, T. O., & Adler, J. R. (1993). MR susceptibility misregistration correction. IEEE Transactions on Medical Imaging, 12(2), 251–259. doi:10.1109/42.232253) Using chi = -11.5 for bone (the other value mentioned in https://github.com/shimming-toolbox/tissue-to-MRproperty/blob/bd3d46ed5d69f3a0401ab38263f769363ed988e7/functions/utils/select_tool.py#L259, from an unknown reference) I find it odd that the values are so much lower directly above the head (below blue, so black) vs in the axial plane outside the head where it's higher ( reaching positive numbers, red), this doesn't make sense to me conceptually from a physics point of view, but I haven't looked at the B0 simulation code |
@mathieuboudreau this is very interesting, right now we are investigating how different susceptibility values affect the fieldmaps. The value for bone was updated after @CharlesPageot did a literature research so he might be able to tell you were this value comes from. Also, in the tissue to MR property, every susceptibilit value is reference to free space so its important to check what it is referenced to. In the paper you mentioned they say its - 8.86 referenced to air. |
This is an important topic because i would also like to confirm the value of susceptibility for cartilage @CharlesPageot. Thanks! |
Good point! I was playing around with sifferent values because i saw two different ones in the dictionnary, shimming-toolbox/tissue-to-MRproperty#15, and couldnt find any references or explanation for this in this code, shimming-toolbox/tissue-to-MRproperty#14. Thats why i started looking for values in references, but itll be a quick update once I know the final chi values to use for each tissue! |
The -11.5 for bone comes from this abstract. In this study, they found a bone susceptibility of -2.46 relative to water. For cartillage @sriosq, i had trouble finding other sources, so I statyed with the value in the Matlab repo which already had a reference. |
Indeed, we will need to deal with this after the ISMRM deadline (maybe we can open a specific issue for this)
Yes! For openneuro, I'm still waiting for the 'OK' from Marseille, but all the other tasks are indeed needed
@Govish can clarify |
I've run the label smoothing & merging script on all subject, converted this merged label map to chi with some values @sriosq suggested to use, and run the chi-to-b0 map software on all subjects, but refactoring so that the padding uses numpy's Here's a GIF of the fieldmap for all subjects (may be slow to load)
Some subjects have blank fieldmaps; the output from the chi-to-b0 software were |
@Govish, are the fieldmaps in the animation in my comment above (gif, may take a few seconds to load) closer to what you were looking for? |
To my untrained eye they look pretty good! I'll check with Jason to see if they seem reasonable to him too. |
about the padding issue, @mathieuboudreau this figure from [Shang Y, Theilenberg S, Terekhov M, Mattar W, Peng B, Jambawalikar SR, Schreiber LM, Juchem C. High-resolution simulation of B0 field conditions in the human heart from segmented computed tomography images. NMR Biomed. 2022 Aug;35(8):e4739.] is possibly of relevance: |
@jcohenadad thanks! I went with edge padding instead of zero padding, since our volume is cut off at the torso unlike them, and that would create a ficticious air-tissue boundary at the torso. Also we have chi outside the body set to air, so zero padding would create another interface |
But, i did notice the effects of padding width to zeroth order B0 values like they seem to have observed |
RE: the topic of this original issue title (bidsifying the dataset), I just finished pushing all the smoothed labels, chi maps, and simulated B0 map to the data.neuro.polymtl.ca in the mb/air-tissue-labels branch of the whole-spine dataset. In addition, I setup my pipelines/functions to automatically generate detailed json-sidecars for each produced NIfTI file after they are saved, hopefully enough so that 1) they can be reproduced, 2) they can be traced back to different versions of the softwares/code used, and 3) provide enough information so that they can be used (i.e. details about what the labels mean, what anatomy was assigned which chi value, etc). Here are some examples for different types of files for one subject: Simulated B0 map: sub-amuALT_T1w_fmap_b0-sim.json {
"author":"mathieuboudreau",
"creation date":"2024-10-31 21:19:48",
"script":"compute_fieldmap",
"script source":"https://github.com/shimming-toolbox/susceptibility-to-fieldmap-fft",
"script commit hash":"d9f785b082fb145d547ff03ae53f23f1564ccc38",
"input file":"/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/sub-amuALT/anat/sub-amuALT_T1w-chi.nii.gz",
"padding":50,
"command":"compute_fieldmap -i /Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/sub-amuALT/anat/sub-amuALT_T1w-chi.nii.gz -o /Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/sub-amuALT/fmap/sub-amuALT_T1w_fmap_b0-sim.nii.gz -b 50 -m b0SimISMRM"
}
Chi map: sub-amuALT_T1w-chi.json {
"author": "mathieuboudreau",
"date": "2024-10-31 21:15:40",
"script": "/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/b0-fieldmap-realistic-simulation/b0realsim/label_to_chi.py",
"script source": "https://github.com/shimming-toolbox/b0-fieldmap-realistic-simulation",
"script commit hash": "30d3e91b5071b6c41c97cfd9abf7b339365e4464",
"input file": "/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-all.nii.gz",
"command": "python label_to_chi.py -s /Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/sub-amuALT",
"anatomy": {
"background": {
"label": 0,
"chi": 0.35
},
"body": {
"label": "1",
"chi": -9.05
},
"sinus": {
"label": 2,
"chi": -2
},
"earcanal": {
"label": 3,
"chi": -2
},
"trachea": {
"label": 4,
"chi": -4.2
},
"rightlung": {
"label": 5,
"chi": -4.2
},
"leftlung": {
"label": 6,
"chi": -4.2
},
"brain": {
"label": 56,
"chi": -9.04
},
"eyes": {
"label": 60,
"chi": -9.05
},
"skull": {
"label": 91,
"chi": -11
},
"verterbae": {
"label": 92,
"chi": -11
},
"disks": {
"label": 93,
"chi": -9.055
},
"canal": {
"label": 100,
"chi": -9.055
}
}
}
Combined labels for all anatomy: sub-amuALT_T1w_label-all.json {
"author": "mathieuboudreau",
"date": "2024-10-31 12:08:01",
"script": "/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/b0-fieldmap-realistic-simulation/b0realsim/merge_labels.py",
"script source": "https://github.com/shimming-toolbox/b0-fieldmap-realistic-simulation",
"script commit hash": "30d3e91b5071b6c41c97cfd9abf7b339365e4464",
"input files": [
"/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-air_tissue.nii.gz",
"/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-canal_seg.nii.gz",
"/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-spine_dseg.nii.gz",
"/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-brain.nii.gz",
"/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-skull.nii.gz",
"/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-eyes.nii.gz",
"/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-skin.nii.gz",
"/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-sinus.nii.gz",
"/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-earcanal.nii.gz",
"/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-body.nii.gz"
],
"anatomy": {
"background": {
"label": 0
},
"body": {
"label": "1"
},
"sinus": {
"label": 2
},
"earcanal": {
"label": 3
},
"trachea": {
"label": 4
},
"rightlung": {
"label": 5
},
"leftlung": {
"label": 6
},
"brain": {
"label": 56
},
"eyes": {
"label": 60
},
"skull": {
"label": 91
},
"verterbae": {
"label": 92
},
"disks": {
"label": 93
},
"canal": {
"label": 100
}
},
"command": "python merge_labels.py -s /Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/sub-amuALT"
}
Anatomical (skull) segmentation after smoothing using Slicer: sub-amuALT_T1w_label-skull.json {
"author": "mathieuboudreau",
"date": "2024-10-31 12:07:31",
"script": "/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/b0-fieldmap-realistic-simulation/b0realsim/slicer_scripts/smooth_segment.py",
"script source": "https://github.com/shimming-toolbox/b0-fieldmap-realistic-simulation",
"script commit hash": "30d3e91b5071b6c41c97cfd9abf7b339365e4464",
"input file": "/Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-skull-raw.nii.gz",
"label": {
"anatomy": "skull",
"value": 1,
"input file value": 1,
"processing steps": {
"islands": {
"operation": "REMOVE_SMALL_ISLANDS"
},
"smoothing": {
"method": "MORPHOLOGICAL_CLOSING",
"kernel_size_mm": 15
},
"grow": {
"margin_mm": 3
},
"shrink": {
"margin_mm": 2
}
}
},
"command": "/Applications/Slicer.app/Contents/MacOS/Slicer --python-script /Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/b0-fieldmap-realistic-simulation/b0realsim/slicer_scripts/smooth_segment.py -m /Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/sub-amuALT/anat/sub-amuALT_T1w.nii.gz -s /Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-skull-raw.nii.gz -o /Users/mathieuboudreau/neuropoly/projects/shimming-toolbox/data/data.neuro.polymtl.ca/whole-spine/derivatives/labels/sub-amuALT/anat/sub-amuALT_T1w_label-skull.nii.gz -a skull",
"slicer version": "5.6",
"slicer repository revision": "f10cd8c"
}
Writing these sidecars were done a bit differently depending on if a shell script or python script generated them; for those interested, here's some of the example code (could be cleaned up and refactored, but time is running short for the ISMRM deadline): Shell script:
Python script: b0-fieldmap-realistic-simulation/b0realsim/slicer_scripts/smooth_segment.py Lines 251 to 277 in 30d3e91
|
Motivation: we want to upload the data to OpenNeuro, so we need to BIDSify them.
The magnitude data are already in BIDS and are located here (internal server): https://data.neuro.polymtl.ca/datasets/whole-spine
The segmentation labels organized by @CharlesPageot are located here.
Here's a tree:
They need to be organized according to BIDS, but for that we need to agree on the organization. Few thoughts:
Additional notes:
whole-spine_samseg_labels
folder name is misleadingImportant
The magnitude BIDS data already include some labels, that were likely generated by @NathanMolinier. I will do some digging to understand what labels already exist, and which ones are duplicates of what @CharlesPageot shared in the GDrive folder.
The text was updated successfully, but these errors were encountered: