def saveDeformedLattice3D(displacement, oname): minVal, maxVal=tf.get_displacement_range(displacement, None) sh=np.array([np.ceil(maxVal[0]),np.ceil(maxVal[1]),np.ceil(maxVal[2])], dtype=np.int32) L=np.array(rcommon.drawLattice3D(sh, 10)) warped=np.array(tf.warp_volume(L, displacement, np.eye(4))).astype(np.int16) img=nib.Nifti1Image(warped, np.eye(4)) img.to_filename(oname)
def saveDeformedLattice3D(displacement, oname): minVal, maxVal = tf.get_displacement_range(displacement, None) sh = np.array([np.ceil(maxVal[0]), np.ceil(maxVal[1]), np.ceil(maxVal[2])], dtype=np.int32) L = np.array(rcommon.drawLattice3D(sh, 10)) warped = np.array(tf.warp_volume(L, displacement, np.eye(4))).astype(np.int16) img = nib.Nifti1Image(warped, np.eye(4)) img.to_filename(oname)
def save_deformed_lattice_3d(displacement, oname): r''' Applies the given displacement to a regular lattice and saves the resulting image to a Nifti file with the given name ''' min_val, max_val = tf.get_displacement_range(displacement, None) shape = np.array([np.ceil(max_val[0]), np.ceil(max_val[1]), np.ceil(max_val[2])], dtype = np.int32) lattice = np.array(rcommon.drawLattice3D(shape, 10)) warped = np.array(tf.warp_volume(lattice, displacement)).astype(np.int16) img = nib.Nifti1Image(warped, np.eye(4)) img.to_filename(oname)
def saveDeformedLattice3D(dname, oname='deformed_lattice.nii.gz'): ''' saveDeformedLattice3D('displacement_templateT1ToIBSR01T1_diff.npy') saveDeformedLattice3D('displacement_templateT1ToIBSR01T1_diffMulti.npy') ''' print 'Loading displacement...' displacement=np.load(dname) minVal, maxVal=tf.get_displacement_range(displacement, None) sh=np.array([np.ceil(maxVal[0]),np.ceil(maxVal[1]),np.ceil(maxVal[2])], dtype=np.int32) print sh.dtype print sh L=np.array(drawLattice3D(sh, 10)) print 'Warping lattice...' warped=np.array(tf.warp_volume(L, displacement, np.eye(4))).astype(np.int16) print 'Transforming to Nifti...' img=nib.Nifti1Image(warped, np.eye(4)) print 'Saving warped lattice as:',oname img.to_filename(oname) print 'done.'