Average DICOM series and save output as new DICOM

31 views
Skip to first unread message

Ariane

unread,
Apr 21, 2024, 8:43:52 AMApr 21
to pydicom
Hi all, I want to average several DICOM series (each series is a 3D volume) and output a DICOM.
The code attached loads each series (stored in a different folder), averages the data (pixel_array) and saves the output with some changes to the metadata. However, this outputs an averaged DICOM with wrong values. It does't seem to be a scaling issue (the voxel values are wrong but not by the same factor) and the error seems to already be present when loading the data. Is there another DICOM tag that should be changed? Or is there another way to do it?

Many thanks,

Ariane
example_pydicom_avg.py

Darcy Mason

unread,
Apr 21, 2024, 1:00:25 PMApr 21
to pydicom
I don't see anything obviously wrong here, but a few suggestions/comments:

- I see that you check pixel data shape is the same between series, but do you know whether that guarantees they match spatially?  The real-world pixel position and orientation (ImagePositionPatient, ImageOrientationPatient) should be checked also, as well as SliceLocation, perhaps others.
- not related to averaging, but SOPInstanceUID should be unique for each file you save
- I'd suggest creating a minimal working example - e.g. two series with only two images each, and stepping through the code with a debugger just before and after the averaging, inspecting the actual values, to narrow down the possible reasons the average is not what you expect.

Ariane

unread,
Apr 22, 2024, 6:48:26 AMApr 22
to pydicom
Thank you for getting back to me!
- I checked ImagePositionPatient, ImageOrientationPatient, SliceLocation, they are consistent and are not the issue. 
- Thanks, I corrected my code with SOPInstanceUID for each file saved.
- Found the error! It was because I was not rescaling the values (each series has a different RescaleSlope). Should I compute the mean array with rescaled values (and then set RescaleSlope to 1) or should compute the RescaleSlope for the averaged array with the original pixel values? 
- Should I also update Window Center and Width ?
Reply all
Reply to author
Forward
0 new messages