Issue when calling readImageDICOMFileSeries twice

Hi, I’m developing a DICOM files volume rendering web application using vtk.js and itk.js
I use the very handy and efficient readImageDICOMFileSeries function.
However, this function returns an undefined image when it is called multiple times, which I need to do.
Here is a jsfiddle illustrating this issue : http://jsfiddle.net/nvmoxy6L/8/
(the console.log statements must be read in the debugger console)
Can anyone help me?

@matt.mccormick might be able to help.

Hi @JC_Buisson,

You may want to try the latest version of itk.js, which has improved support for repeated calls.

Note that the arguments to readImageDICOMFileSeries changed in recent versions of itk.js. Now, you only past the file list, and optionally whether the list is known to be a single sorted series (if so, it will improve performance).

We are updating the examples to use the new API.

It still doesn’t work with latest version 12.3.1 : http://jsfiddle.net/0pc4nz2r/
It’s strange: the first call always works nice, but the second is unreliable: it succeeds or fails (it does not throw an error but returns undefined), with the same set of files, in circumstances I cannot explain. Yesterday the fiddle worked ok and this morning it does not, with the same files.

2 Likes

@JC_Buisson thanks for creating the JS fiddle! This is very helpful for reproducibility.

I suspect that it has to do with how memory is handled in JavaScript – I will investigate.

However, you likely want to just create a copy of the itk/Image data structure instead of reading again regardless, since reading requires parsing all the DICOM tags, etc.

In my application, I handle all the DICOM files hierarchy from the CDROM which is given to a patient after a CT exam, using <input type="file" multiple webkitdirectory />. I first parse their meta-data using dicom-parser library, and then find the subset of files which contains the main series. But when I apply readImageDICOMFileSeries to this subset, it fails, apparently because of the prior use of dicom-parser.
After many attempts, I found out that calling the readImageDICOMFileSeries function twice also failed - that’s why I presented this case for easier reproducibility. But the initial use-case is common and I cannot handle it with the method you suggest.

Cool, we added a new argument recently in itk.js to improve performance for this use case – singleSortedSeries can be set to true when calling readImageDICOMSeries in this case.

vtk.js - JSFiddle - Code Playground

This issue here is

let { image2 } = await itk.readImageDICOMFileSeries(files)

The object returned by readImageDICOMFileSeries has the property image. So, the syntax to return the variable in the second call as image2 is:

let { image:image2 } = await itk.readImageDICOMFileSeries(files)

@agirault

You’re right, sorry and thank you! I’ll let you know if the use case I described still has an issue. Keep the good work!

1 Like