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

Fix DICOM export in ImageJ #4215

Merged
merged 4 commits into from
Sep 13, 2024
Merged

Conversation

melissalinkert
Copy link
Member

See https://forum.image.sc/t/exporting-a-dicom-stack/99400/6

I was able to reproduce the exception in that thread using ImageJ + Bio-Formats 7.3.1 by selecting File > Open Samples > Organ of Corti..., then Plugins > Bio-Formats > Bio-Formats Exporter and saving to a file with the .dcm extension.

With this change, the same test should result in a converted .dcm file (with no exception) that can be re-opened.

This caused a problem when exporting DICOM with multiple channels from ImageJ,
as the DICOM writer strictly requires non-null SamplesPerPixel on every Channel.
Shouldn't affect bfconvert, but does affect ImageJ export which calls
close() twice.
@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/exporting-a-dicom-stack/99400/8

@sbesson sbesson self-requested a review September 2, 2024 13:24
@sbesson sbesson added this to the 8.0.0 milestone Sep 2, 2024
Copy link
Member

@sbesson sbesson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the current release JARS (7.3.1) shipped in the Java-8 distribution, I was able to reproduce the exception described in the PR while exporting the sample file as a DICOM.

Using the JARs built from this branch and replacing them in my local distribution, the same sample file exports successfully using the exporter and can be reopened with the plugin.

Testing the export of a few other sample files, I came across another NPE using ``File > Open Samples > Cardio (RGB DICOM)` and selecting the Bio-Formats exporter to create a DICOM

java.lang.NullPointerException
	at loci.formats.out.DicomWriter.setId(DicomWriter.java:1057)
	at loci.formats.FormatWriter.changeOutputFile(FormatWriter.java:123)
	at loci.plugins.out.Exporter.run(Exporter.java:815)
	at loci.plugins.LociExporter.run(LociExporter.java:75)
	at ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:266)
	at ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:114)
	at ij.IJ.runUserPlugIn(IJ.java:246)
	at ij.IJ.runPlugIn(IJ.java:210)
	at ij.IJ.runPlugIn(IJ.java:199)
	at loci.plugins.shortcut.ShortcutPanel$1.run(ShortcutPanel.java:189)
	Suppressed: java.lang.NullPointerException
		at loci.formats.out.DicomWriter.writeIFDs(DicomWriter.java:2008)
		at loci.formats.out.DicomWriter.close(DicomWriter.java:1402)
		at loci.plugins.out.Exporter.run(Exporter.java:343)
		... 7 more

Is that something we also want to fix as part of this PR?

@melissalinkert
Copy link
Member Author

Testing the export of a few other sample files, I came across another NPE using ``File > Open Samples > Cardio (RGB DICOM)` and selecting the Bio-Formats exporter to create a DICOM

ab8234f is one way to handle, but open to other ideas.

@sbesson
Copy link
Member

sbesson commented Sep 12, 2024

ab8234f is one way to handle, but open to other ideas.

No objections to this approach from my side. The proposal is very similar to glencoesoftware/omero-ms-image-region#99 which was addressing a very similar use case. In the same spirit, could the private method handle separately the null case from the unsupported length units case and log a warning level statement in the latter case to communicate that metadata is lost on conversion?

@sbesson
Copy link
Member

sbesson commented Sep 13, 2024

Successfully tested by exporting a few ImageJ samples (Cardio (RGB DICOM), CT (16-bit DICOM), Organ of Corti (4D stack)) as DICOM and rereading them in Fiji modified with the JARs built from this PR.

Noticed that if all DICOM files are exported in the same folder, the initialization fails as I assume the reader tries to read multiple DICOM files in the same directory. But this is the current behavior and was not introduced by this PR

@sbesson sbesson merged commit e431517 into ome:develop Sep 13, 2024
18 checks passed
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 this pull request may close these issues.

3 participants