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

Use bids entities if available in the output name #909

Open
marcelzwiers opened this issue Jan 17, 2025 · 6 comments
Open

Use bids entities if available in the output name #909

marcelzwiers opened this issue Jan 17, 2025 · 6 comments

Comments

@marcelzwiers
Copy link

marcelzwiers commented Jan 17, 2025

If I convert a Series folder containing multiple images (e.g. magnitude + phase or multiple echos), then dcm2niix add a post-fix to the name. Fair enough. But it would be nice if, instead of appending postfix, dcm2niix would check the output name for a corresponding bids-entity and use that for disambiguation. For instance, for converting a multi-echo VFA scan I would run:

dcm2niix {args} -f "sub-001_echo-1_part-mag_VFA" -o {outfolder} {sourcefolder}

As an output, I get multiple images with _e and _ph post-fixes, which I then need to strip post-hoc from the filename and store the info in the corresponding echo and part key-value pairs. It would be useful if dcm2niix would first check the output filename for corresponding bids-entities and use those instead of appending post-fixes. Of course, for backwards compatibility such a feature can be a user option

@neurolabusc
Copy link
Collaborator

The challenge is that this approach does not work across all manufacturers and operating systems, or even all BIDS situations. The high performance of dcm2niix derives from the fact that it converts all DICOM data in a single pass, converting one series at a time. Unfortunately, manufacturers often specify the total number of echoes. Due to variations in these properties, one can end up with name clashing if the post-fix is not added (you can explore this with the --terse conversion). Likewise, some BIDS intentions require properties like phase and magnitude to be appended to the filename, rather than being encoded by key-value pairs in the json. Understanding the intention of the files is really aided by looking across the series (e.g. a spin-echo EPI sequence without b-weighting could either be a b=0 series for a diffusion series, or the pepolar sequence for an fMRI series). For these reasons, one typically uses a wrapper such as your bidscoin or an alternative to convert DICOMs to BIDS in two passes: first dcm2niix converts the images as defined solely on the DICOMs, and subsequently a wrapper uses information about the intention to provide the proper BIDS naming.

It is worth noting that dcm2niix does have the experimental BidsGuess option, that can resolve a lot more than the classic dcm2niix conversion. However, it has really only been trained on the clinical datasets I am working with. You can try that feature out to see if it is useful for you (the latest version also inserts the BidsGuess key:value into the JSON that you may or may not find useful).

@marcelzwiers
Copy link
Author

I understand the challenges and I am aware that the problem arises from manufacturers storing multiple images in a single Series folder (as I deal with this in bidscoin), but as I see it you could use the BIDS entities if available in the output name, and else just use the existing post-fixes as a fallback (pareto principle)? I think bidsguess is not useful for my situation, because in BIDScoin I already know exactly what the (BIDS compliant) output name should be -- but then I need to strip the postfixes and put them in the output name once more.

@marcelzwiers
Copy link
Author

Anyhow, it was just a thought and I already have (ugly) workarounds for the postfixes in place, so you can close the issue if you like

@marcelzwiers
Copy link
Author

marcelzwiers commented Jan 21, 2025

The pseudocode I propose would be something like (e.g. for dealing multiples echos in one folder):

if use_entities and '_echo-' in outputname:
   outputname.replace(old_echonr, postfix_echonr)  # in practice use a regex (old_echonr is parsed from the outputname)
else:
   outputname.append('_e'+ postfix_echonr)

@neurolabusc
Copy link
Collaborator

@marcelzwiers since you know the complete filename, the --terse option seems to solve your problem.

@marcelzwiers
Copy link
Author

No, because even if I know the exact filename, I still cannot control how many images there are in one Series folder

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

No branches or pull requests

2 participants