SyneRBI / SIRF-Exercises

SIRF Training and demonstration material
http://www.ccpsynerbi.ac.uk
Apache License 2.0
17 stars 21 forks source link

Singleton first dimension problems in BrainWeb-single_slice_motion.ipynb #154

Closed DANAJK closed 2 years ago

DANAJK commented 2 years ago

BrainWeb-single_slice_motion.ipynb

After FDG_arr = vol['PET'], the shape of FDG_arr is (127,344,344).

Then after slice = FDG_arr.shape[0]//2 FDG_arr = FDG_arr[slice,:,:]

FDG_arr has shape (344,344) (i.e. there has been a secret squeeze). This subsequently causes problems with im.fill(vol) because vol is derived from FDG_arr and is thus 2D (despite the name vol), whereas im is 3D (despite the name) and has a singleton first dimension so you can't fill im with vol.

paskino commented 2 years ago

I guess we need to use numpy expand_dims

Something like this might work


vol = np.expand_dims(vol, axis=0)
DANAJK commented 2 years ago

Also the BrainWeb notebook

NicoleJurjew commented 2 years ago

I changed the BrainWeb-single_slice_motion.ipynb notebook. @DANAJK is right, the same function is implemented in the BrainWeb notebook. It deals with the entire 3D array rather than cropping to a 2D image, though, so the error doesn't occur in the BrainWeb notebook for me.