Esempio n. 1
0
def create_files_in_directory():
    outdir = mkdtemp()
    cwd = os.getcwd()
    os.chdir(outdir)
    filelist = ['a.nii','b.nii']
    for f in filelist:
        hdr = nif.Nifti1Header()
        shape = (3,3,3,4)
        hdr.set_data_shape(shape)
        img = np.random.random(shape)
        nif.save(nif.Nifti1Image(img,np.eye(4),hdr),
                 os.path.join(outdir,f))
    return filelist, outdir, cwd
import nipype.externals.pynifti as nb
import numpy as np

image_filename2 = "/media/sdb2/laura_study/DATA_4_chis/SPGRs/AG_1247/T2.hdr"

nii2 = nb.load(image_filename2)

affine = nii2.get_affine()
flip_matrix = np.eye(4)
#flip_matrix[0,0] = -1
affine = np.dot(flip_matrix,affine)

data = nii2.get_data()

nb.save(nb.Nifti1Image(data, affine, nii2.get_header()), "new_T2.nii")
Esempio n. 3
0
#
#mean_dist = np.mean(dist_matrix)
#
#print mean_dist








border1 = findBorder(origdata1)
print np.sum(border1)

nb.save(nb.Nifti1Image(border1, nii1.get_affine(), nii1.get_header()), "border1.nii")

nii2 = nb.load(image_filename2)
origdata2 = nii2.get_data().astype(np.bool)
border2 = findBorder(origdata2)
print np.sum(border2)
nb.save(nb.Nifti1Image(border2, nii2.get_affine(), nii2.get_header()), "border2.nii")

set1_coordinates = getCoordinates(border1, nii1.get_affine())
print set1_coordinates.T.shape

set2_coordinates = getCoordinates(origdata2, nii2.get_affine())
print set2_coordinates.T.shape

dist_matrix = cdist(set1_coordinates.T, set2_coordinates.T)
print dist_matrix.shape