moloney / dcmstack

DICOM to Nifti conversion with meta data preservation
Other
72 stars 51 forks source link

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

Open junliu-cn opened 6 years ago

junliu-cn commented 6 years ago

image anyone help me? Thx!

isolovey commented 6 years ago

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 commented 6 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 1 year ago

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.