Ejemplo n.º 1
0
    def implement(self):
        anat = self.getPreparationImage('anat')

        # Look if a freesurfer tree is already available
        if not self.__findAndLinkFreesurferStructure():
            self.__submitReconAll(anat)
            # @TODO backup the recon-all to backup dir

        if not self.__findImageInDirectory(
                "brainstemSsLabels.v10.FSvoxelSpace.mgz",
                os.path.join(self.workingDir, self.id)):
            self.__submitSubSegmentation(anat, 'brainstem')
        if not self.__findImageInDirectory(
                "rh.hippoSfLabels-T1.v10.FSvoxelSpace.mgz",
                os.path.join(self.workingDir, self.id)):
            self.__submitSubSegmentation(anat, 'hippocampus')

        self.__convertFreesurferImageIntoNifti(anat)
        self.__createSegmentationMask(self.get('aparc_aseg'), self.get('mask'))
        self.__mergeParcellation(self.get('wmparc'), self.get('aparc_aseg'),
                                 self.get('brainstem'), self.get('lhHipp'),
                                 self.get('rhHipp'))
        tt5Mgz = self.__create5ttImage()
        mriutil.convertAndRestride(
            tt5Mgz, self.get('tt5'),
            self.get('preparation', 'stride_orientation'))
        anatFreesurfer = self.getImage('anat', 'freesurfer')

        if self.get('cleanup'):
            self.__cleanup()
Ejemplo n.º 2
0
    def __createImageFromAtlas(self, source, target):
        """
            Create a area map base on a source name
        Args:
            source: template name as specify into config.cfg
            target: output file name

        Returns:
            A brodmann area images

        """
        tmpImage = 'tmp_{0:.6g}.mgz'.format(random.randint(0,999999))
        template = os.path.join(self.toadDir, "templates", "mri", self.get(source))

        self.info("Set SUBJECTS_DIR to {}".format(self.parcellationDir))
        os.environ["SUBJECTS_DIR"] = self.parcellationDir

        cmd = "mri_vol2vol --mov {} --targ $FREESURFER_HOME/subjects/fsaverage/mri/T1.mgz" \
              " --o {} --regheader --interp nearest".format(template, tmpImage)
        self.launchCommand(cmd)

        cmd =  "mri_vol2vol --mov $SUBJECTS_DIR/{0}/mri/norm.mgz --targ {1} --s {0} " \
               " --m3z talairach.m3z --o {2} --interp nearest --inv-morph".format(self.get('parcellation', 'id'), tmpImage, target)
        self.launchCommand(cmd)
        return mriutil.convertAndRestride(target, target, self.get('preparation', 'stride_orientation'))
Ejemplo n.º 3
0
    def __createImageFromAtlas(self, source, target):
        """
            Create a area map base on a source name
        Args:
            source: template name as specify into config.cfg
            target: output file name

        Returns:
            A brodmann area images

        """
        tmpImage = 'tmp_{0:.6g}.mgz'.format(random.randint(0,999999))
        template = os.path.join(self.toadDir, "templates", "mri", self.get(source))

        self.info("Set SUBJECTS_DIR to {}".format(self.parcellationDir))
        os.environ["SUBJECTS_DIR"] = self.parcellationDir

        cmd = "mri_vol2vol --mov {} --targ $FREESURFER_HOME/subjects/fsaverage/mri/T1.mgz" \
              " --o {} --regheader --interp nearest".format(template, tmpImage)
        self.launchCommand(cmd)

        cmd =  "mri_vol2vol --mov $SUBJECTS_DIR/{0}/mri/norm.mgz --targ {1} --s {0} " \
               " --m3z talairach.m3z --o {2} --interp nearest --inv-morph".format(self.get('parcellation', 'id'), tmpImage, target)
        self.launchCommand(cmd)
        return mriutil.convertAndRestride(target, target, self.get('preparation', 'stride_orientation'))
Ejemplo n.º 4
0
    def implement(self):

        anat = self.getPreparationImage('anat')

        # Look if a freesurfer tree is already available
        if not self.__findAndLinkFreesurferStructure():
            self.__submitReconAll(anat)
            # @TODO backup the recon-all to backup dir

        self.__convertFeesurferImageIntoNifti(anat)
        self.__createSegmentationMask(self.get('aparc_aseg'), self.get('mask'))
        tt5Mgz = self.__create5ttImage()
        mriutil.convertAndRestride(tt5Mgz, self.get('tt5'), self.get('preparation', 'stride_orientation'))
        anatFreesurfer = self.getImage('anat', 'freesurfer')

        if self.get('cleanup'):
            self.__cleanup()
Ejemplo n.º 5
0
    def __convertFeesurferImageIntoNifti(self, anatomicalName):

        """
            Convert a List of mgz fresurfer into nifti compress format

        Args:
            anatomicalName: The subject anatomical image is need to identify the proper T1

        """
        for (target, source) in [(self.buildName(anatomicalName, 'freesurfer'), "T1.mgz"),
                                    (self.get('aparc_aseg'), "aparc+aseg.mgz"),
                                    (self.get('wmparc'), "wmparc.mgz"),
                                    (self.get('rh_ribbon'), "rh.ribbon.mgz"),
                                    (self.get('lh_ribbon'), "lh.ribbon.mgz"),
                                    (self.get('norm'), "norm.mgz")]:

            mriutil.convertAndRestride(self.__findImageInDirectory(source, os.path.join(self.workingDir, self.id)),
                                       target,
                                       self.get('preparation', 'stride_orientation'))
Ejemplo n.º 6
0
    def implement(self):
        anat = self.getPreparationImage('anat')

        # Look if a freesurfer tree is already available
        if not self.__findAndLinkFreesurferStructure():
            self.__submitReconAll(anat)
            # @TODO backup the recon-all to backup dir

        if not self.__findImageInDirectory("brainstemSsLabels.v10.FSvoxelSpace.mgz", os.path.join(self.workingDir, self.id)):
            self.__submitSubSegmentation(anat, 'brainstem')
        if not self.__findImageInDirectory("rh.hippoSfLabels-T1.v10.FSvoxelSpace.mgz", os.path.join(self.workingDir, self.id)):
            self.__submitSubSegmentation(anat, 'hippocampus')

        self.__convertFreesurferImageIntoNifti(anat)
        self.__createSegmentationMask(self.get('aparc_aseg'), self.get('mask'))
        self.__mergeParcellation(self.get('wmparc'),self.get('aparc_aseg'),self.get('brainstem'),self.get('lhHipp'),self.get('rhHipp'))
        tt5Mgz = self.__create5ttImage()
        mriutil.convertAndRestride(tt5Mgz, self.get('tt5'), self.get('preparation', 'stride_orientation'))
        anatFreesurfer = self.getImage('anat', 'freesurfer')

        if self.get('cleanup'):
            self.__cleanup()
Ejemplo n.º 7
0
    def __convertFreesurferImageIntoNifti(self, anatomicalName):
        """
            Convert a List of mgz fresurfer into nifti compress format

        Args:
            anatomicalName: The subject anatomical image is need to identify the proper T1

        """
        for (target, source) in [
            (self.buildName(anatomicalName, 'freesurfer'), "T1.mgz"),
            (self.get('aparc_aseg'), "aparc+aseg.mgz"),
            (self.get('wmparc'), "wmparc.mgz"),
            (self.get('rh_ribbon'), "rh.ribbon.mgz"),
            (self.get('lh_ribbon'), "lh.ribbon.mgz"),
            (self.get('brainstem'), "brainstemSsLabels.v10.FSvoxelSpace.mgz"),
            (self.get("rhHipp"), "rh.hippoSfLabels-T1.v10.FSvoxelSpace.mgz"),
            (self.get("lhHipp"), "lh.hippoSfLabels-T1.v10.FSvoxelSpace.mgz"),
            (self.get('norm'), "norm.mgz")
        ]:

            mriutil.convertAndRestride(
                self.__findImageInDirectory(
                    source, os.path.join(self.workingDir, self.id)), target,
                self.get('preparation', 'stride_orientation'))