# Issue when calling readImageDICOMFileSeries twice

**URL:** https://discourse.itk.org/t/issue-when-calling-readimagedicomfileseries-twice/2993
**Category:** Beginner Questions
**Created:** [April 22, 2020, 3:12pm UTC](https://discourse.itk.org/t/issue-when-calling-readimagedicomfileseries-twice/2993 "2020-04-22T15:12:06Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![JC\_Buisson](https://discourse.itk.org/user_avatar/discourse.itk.org/jc_buisson/32/1412_2.png) [@JC\_Buisson](https://discourse.itk.org/u/JC_Buisson)
#### Post date: [April 22, 2020, 3:12pm UTC](https://discourse.itk.org/t/issue-when-calling-readimagedicomfileseries-twice/2993/1 "2020-04-22T15:12:07Z")

</div>

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/](http://jsfiddle.net/nvmoxy6L/8/)  
(the console.log statements must be read in the debugger console)  
Can anyone help me?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [April 22, 2020, 6:28pm UTC](https://discourse.itk.org/t/issue-when-calling-readimagedicomfileseries-twice/2993/2 "2020-04-22T18:28:32Z")

</div>

@matt.mccormick might be able to help.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 23, 2020, 6:37pm UTC](https://discourse.itk.org/t/issue-when-calling-readimagedicomfileseries-twice/2993/3 "2020-04-23T18:37:03Z")

</div>

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`](https://insightsoftwareconsortium.github.io/itk-js/api/browser_io.html#readImageDICOMFileSeries-fileList-singleSortedSeries-false-gt-image-webWorkerPool) 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.

---

<div class="post-metadata">

### Author: ![JC\_Buisson](https://discourse.itk.org/user_avatar/discourse.itk.org/jc_buisson/32/1412_2.png) [@JC\_Buisson](https://discourse.itk.org/u/JC_Buisson)
#### Post date: [April 24, 2020, 4:59am UTC](https://discourse.itk.org/t/issue-when-calling-readimagedicomfileseries-twice/2993/4 "2020-04-24T04:59:35Z")

</div>

It still doesn’t work with latest version 12.3.1 : [http://jsfiddle.net/0pc4nz2r/](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.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 27, 2020, 5:16pm UTC](https://discourse.itk.org/t/issue-when-calling-readimagedicomfileseries-twice/2993/5 "2020-04-27T17:16:44Z")

</div>

> [@JC\_Buisson](#):
>
> [vtk.js - JSFiddle - Code Playground](http://jsfiddle.net/0pc4nz2r/)

@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.

---

<div class="post-metadata">

### Author: ![JC\_Buisson](https://discourse.itk.org/user_avatar/discourse.itk.org/jc_buisson/32/1412_2.png) [@JC\_Buisson](https://discourse.itk.org/u/JC_Buisson)
#### Post date: [April 28, 2020, 5:02am UTC](https://discourse.itk.org/t/issue-when-calling-readimagedicomfileseries-twice/2993/6 "2020-04-28T05:02:22Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 29, 2020, 3:44pm UTC](https://discourse.itk.org/t/issue-when-calling-readimagedicomfileseries-twice/2993/7 "2020-04-29T15:44:09Z")

</div>

> [@JC\_Buisson](#):
>
> . I first parse their meta-data using `dicom-parser` library, and then find the subset of files which contains the main series.

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](http://jsfiddle.net/0pc4nz2r/)

This issue here is

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

```

The [object returned by `readImageDICOMFileSeries`](https://insightsoftwareconsortium.github.io/itk-js/api/browser_io.html#readImageDICOMFileSeries-fileList-singleSortedSeries-false-gt-image-webWorkerPool) has the property `image`. So, the syntax to return the variable in the second call as `image2` is:

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

```

@agirault

---

<div class="post-metadata">

### Author: ![JC\_Buisson](https://discourse.itk.org/user_avatar/discourse.itk.org/jc_buisson/32/1412_2.png) [@JC\_Buisson](https://discourse.itk.org/u/JC_Buisson)
#### Post date: [April 30, 2020, 4:37am UTC](https://discourse.itk.org/t/issue-when-calling-readimagedicomfileseries-twice/2993/8 "2020-04-30T04:37:58Z")

</div>

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!
