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

dcmstack.dcmstack.InvalidStackError: The DICOM stack is not valid: Slice spacings are not consistent #55

Open
junliu-cn opened this issue Dec 1, 2017 · 8 comments

Comments

@junliu-cn
Copy link

image
anyone help me? Thx!

@isolovey
Copy link

isolovey commented Dec 1, 2017

Are slice spacings inconsistent? If you read the image position attribute (0020,0032) from each slice, are the slices equally spaced (may or may not be as simple as looking at the z coordinate depending on whether your FOV is oblique)?

@moloney
Copy link
Owner

moloney commented Apr 17, 2018

I have increased the tolerance a few times (mostly to accommodate GE data). It would be good to know if this is a case of the tolerances still being too small? Or are you missing some slices?

@bjw34032
Copy link

I have Siemens data where the values from ._slice_pos_val indicate non-uniform slice thickness; e.g.,

Difference between slices
[1.59999994 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994
 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994
 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994
 1.59999994 1.59999994 1.59999994 3.19999988 1.59999994 1.59999994
 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994
 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994
 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994
 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994 1.59999994
 1.59999994 1.59999994]

...but I think this is an error. Can the information in ._slice_pos_val be modified by providing it a new vector/list/set?

@moloney
Copy link
Owner

moloney commented Mar 13, 2020

That looks exactly like a missing slice (one spacing is doubled), why would the DICOM meta data have the wrong position information?

If you want to "fix" this you would need to edit the DICOM dataset before passing it in to dcmstack, but in this case that would mean shifting every DICOM from one side of the gap over one space.

@bjw34032
Copy link

Good point, thank-you for your comments. I know it's strange but this is a normalized (i.e., NORM in the ImageType field) version of a series that has correct slice positions. It's just not possible to have one of them correct and the other incorrect since they come from the same data. I have other examples there the difference between slices goes from 1.5999 to -81.54999 for a single slice and then back to 1.5999. That clearly can't be correct. Visually the data look fine.

I perform all my processing in python since I have to deal with ~40,000 datasets, automation is key. I have used your dcmstack code for years now and it's great! I will look into pydicom and its ability to read-edit-write DICOM files.

@moloney
Copy link
Owner

moloney commented Mar 18, 2020

It sounds like someone might have edited the DICOM meta data incorrectly then? A common mistake is for people to not update all of the UIDs when they write modified copies, and then you end up with multiple different copies of the data in the same DICOM series.

I have yet to see a valid MRI data set with non-uniform slice spacing, and in fact the Nifti format doesn't support non-uniform slicing. I guess it happens with CT sometimes, and in order to support converting that to Nifti you would need some sort of resampling scheme.

@Danie1Hayes
Copy link

It sounds like someone might have edited the DICOM meta data incorrectly then? A common mistake is for people to not update all of the UIDs when they write modified copies, and then you end up with multiple different copies of the data in the same DICOM series.

I have yet to see a valid MRI data set with non-uniform slice spacing, and in fact the Nifti format doesn't support non-uniform slicing. I guess it happens with CT sometimes, and in order to support converting that to Nifti you would need some sort of resampling scheme.

Hey!Thanks a lot for your code. I' m working on a CT dataset.
I stored all the files in different folders according to StudyInstanceID, and most of them can be processed correctly, but when processing some files, same error will be prompted.
and What do you mean by re-sampling CT?

@moloney
Copy link
Owner

moloney commented Feb 10, 2023

You would need to interpolate the data onto a uniform grid before storing into a Nifti, and presumably you would want to choose the minimum spacing as the grid resolution which is potentially quite wasteful. The meta data would also need special handling, as would be introducing a bunch of "virtual slices" that don't have DICOM meta data.

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

5 participants