Py-rex icon indicating copy to clipboard operation
Py-rex copied to clipboard

Incorrect slice alignment when rounding ImagePositionPatient[2] to int

Open nickhardcastle opened this issue 2 years ago • 0 comments

Hi,

We've discovered an issue with PyrexReader whereby using int(ImagePositionPatient[2]) incorrectly orders slices in both the image and mask.

At line 56: scan.sort(key = lambda x: int(x.ImagePositionPatient[2])) # sort slices based on Z coordinate

We get incorrectly ordered CT slices (see attachment #1) 2022-05-03 12_26_07-3D Slicer 4 11 20210226

Replacing with: scan.sort(key = lambda x: float(x.ImagePositionPatient[2])) # sort slices based on Z coordinate

And at line 110: if np.int64(Cpostion_rt) == np.int64(img_vol[i].ImagePositionPatient[2]):

Replacing with: if float(Cpostion_rt) == float(img_vol[i].ImagePositionPatient[2]):

we get correctly aligned slices for both the CT and the structure mask (see attachment #2) 2022-05-03 12_25_01-3D Slicer 4 11 20210226

This only happens for some CT data sets, still trying to figure out which factors lead to this. It's only visible if you put a line in at the end of PyrexReader to export the images/masks (or an image showing a slice through this). We've since added code to visualise the image/mask as it comes out of PyrexReader to review as a QA check.

Cheers,

Nick

nickhardcastle avatar May 03 '22 02:05 nickhardcastle