Ejemplo n.º 1
0
	def __init__(self, imgfile, datafile=None, subject=None, group=None, convert=True):
		
		self.name = imgfile.split('/')[-1].split('.')[0]
		self.json = imageutils.img_to_json(imgfile)
		# If image is in Analyze format, write NIFTI copy
		if convert and re.match('img', imgfile):
			img = NiftiImage(imgfile)
			img.save('%s.nii.gz' % self.name)
Ejemplo n.º 2
0
    def __init__(self,
                 imgfile,
                 datafile=None,
                 subject=None,
                 group=None,
                 convert=True):

        self.name = imgfile.split('/')[-1].split('.')[0]
        self.json = imageutils.img_to_json(imgfile)
        # If image is in Analyze format, write NIFTI copy
        if convert and re.match('img', imgfile):
            img = NiftiImage(imgfile)
            img.save('%s.nii.gz' % self.name)
Ejemplo n.º 3
0
    def save(self, image):
        nifti_image = NiftiImage(image.data)
        spacing = image.spacing.tolist()
        spacing.reverse()
        nifti_image.pixdim = spacing
        #        logging.warning("Image direction and origin will not be saved")
        nifti_image.save(self._filename)

        # Save gradient direction file if saving NIfTI
        if "mr_diffusion_sequence" in image.metadata:
            gradients = [[], [], []]
            b_values = []
            for diffusion in image.metadata["mr_diffusion_sequence"]:
                gradient = diffusion.diffusion_gradient_direction_sequence[
                    0].diffusion_gradient_orientation
                b_value = diffusion.diffusion_bvalue

                for index, value in enumerate(gradient):
                    gradients[index].append(str(value))
                b_values.append(str(b_value))

            gradients = "\n".join(
                [" ".join(direction) for direction in gradients])
            b_values = " ".join(b_values)

            base_name = os.path.splitext(self._filename)[0]
            if base_name.endswith(".nii"):
                base_name = os.path.splitext(base_name)[0]

            gradients_file = open("{0}.bvec".format(base_name), "w")
            gradients_file.write(gradients)
            gradients_file.close()

            bvalues_file = open("{0}.bval".format(base_name), "w")
            bvalues_file.write(b_values)
            bvalues_file.close()
Ejemplo n.º 4
0
def write_nifti_file(settings, basename):
    """Write data <basename>.nii."""
    nim = NiftiImage(get_data(settings))
    filename = basename + '.nii'
    print 'Writing data to the nifti file ' + filename + '.'
    nim.save(filename)
Ejemplo n.º 5
0
def write_nifti_file(settings, basename):
    """Write data <basename>.nii."""
    nim = NiftiImage(get_data(settings))
    filename = basename+'.nii'
    print 'Writing data to the nifti file '+filename+'.'    
    nim.save(filename)