def transform(floating, T, reference=None, interp_order=3): # Convert assumed nibabel-like input images to local image class floating = Image(floating) if not reference == None: reference = Image(reference) return asNifti1Image(floating.transform(np.asarray(T), grid_coords=False, reference=reference, interp_order=interp_order))
if ID == 3: PATIENT = '3_axial_FLIPPED_ADJUSTED.nii' THRESHOLD = 300 elif ID == 4: PATIENT = '4LSAG25_5_sagittal_TSE_ADJUSTED.nii' THRESHOLD = 100 elif ID == 5: PATIENT = '05_3DT1_ACPC_Aligned.nii' THRESHOLD = 0 # Create a registration instance print('Creating matcher instance') J = Image(load(join(DATADIR, PATIENT))) J = J[np.where(J.data>THRESHOLD)] ## masking I = Image(load(join(DATADIR, REFERENCE))) R = IconicRegistration(I, J) #R.set_source_fov(fixed_npoints=64**3) R.similarity = SIMI R.interp = INTERP # Affine registration if 'id' in TYPE: T = Affine() elif 'rig' in TYPE: T = R.optimize(Rigid()) elif 'aff' in TYPE:
import numpy as np from nibabel import load from nipy.neurospin.image import Image from os.path import join import scipy.ndimage as nd datadir = 'D:\home\Alexis\data\delphine\zozo' path = join(datadir, 'BiasCorIm.img') # Usecase 0: load an image I = Image(load(path)) # Usecase 1: image masking I1 = I.set_mask(np.where(I.data>100)) # Usecase 2: define a regular image patch (subgridding) I2 = I[5:10:2, 5:10:2, 5:10:2] # Usecase 3: get all masked values in an image tmp = I2.values() # Usecase 4: image interpolation XYZ = 100*np.random.rand(3,10) tmp = I.values(XYZ) # Usecase 4: move an image using an affine transformation T = np.eye(4) T[0:3,3] = 10*np.random.rand(3) J = I.transform(T)
import numpy as np from nibabel import load, save from nipy.neurospin.image import Image, asNifti1Image from os.path import join from glob import glob datadir = join('d:\\', 'home', 'Alexis', 'data', 'remy') I = Image(load(join(datadir, '2_axial_FL_AD_ROI.nii'))) defmodes = glob(join(datadir, 'NEW_SDF', 'SDF_*.nii')) data = np.zeros(list(I.shape)+[len(defmodes)]) for i in range(len(defmodes)): print('image: %d (%s)' % (i, defmodes[i])) m = Image(load(defmodes[i])) mm = m.transform(np.eye(4), reference=I) data[:,:,:,i] = mm.data save(asNifti1Image(Image(data, I.affine)), join(datadir, 'deformation_modes.nii'))