コード例 #1
0
ファイル: 05-correction.py プロジェクト: bpinsard/toad
    def __validateSizeAndDimension(self, *args):

        names = []
        dims = []
        sizes = []

        for source in args:
            if source:
                names.append(source)
                dimensions = mriutil.getMriDimensions(source)
                if len(dimensions) == 4:
                    dims.append([dimensions[0], dimensions[1], dimensions[2]])
                else:
                    dims.append(dimensions)
                    # sourceSize sanitization
                    sourceSize = mriutil.getMriVoxelSize(source)
                    try:
                        sourceSize = [
                            "{:.1f}".format(float(val)) for val in sourceSize
                        ]
                    except ValueError:
                        self.error("Error during sourceSize sanitization")
                    sizes.append(sourceSize)

        if not dims[1:] == dims[:-1]:
            self.error(
                "Dimension for each scale mismatch found between images: {}".
                format(", ".join(names)))

        if not sizes[1:] == sizes[:-1]:
            self.error("Voxel size mismatch found between images: {}".format(
                ", ".join(names)))
コード例 #2
0
ファイル: 06-upsampling.py プロジェクト: UNFmontreal/toad
    def implement(self):

        dwi = self.__linkDwiImage()

        bVals= self.getCorrectionImage('grad', None, 'bvals')
        bVecs= self.getCorrectionImage('grad', None, 'bvecs')
        bEnc = self.getCorrectionImage('grad', None, 'benc')
        if not bVals or not bVecs:
            bVals= self.getPreparationImage('grad', None, 'bvals')
            bVecs= self.getPreparationImage('grad', None, 'bvecs')
            bEnc= self.getPreparationImage('grad', None, 'benc')

        bVals = util.symlink(bVals, self.workingDir)
        bVecs = util.symlink(bVecs, self.workingDir)
        bEnc = util.symlink(bEnc, self.workingDir)

        if self.get('skipUpsampling'):
            dwiUpsample = self.rename(os.path.join(self.workingDir, os.path.basename(dwi)), self.buildName(dwi, "upsample"))
        else:
            interp = self.get('interp')
            template = self.getParcellationImage('anat','freesurfer','nii.gz')

            voxelSize = mriutil.getMriVoxelSize(template) # Get t1 voxel size to upsample
            voxelSize = str(voxelSize).translate(None, '[],') # Remove specific caracteres 

            dwiUpsample= self.__upsampling(dwi, voxelSize, interp, self.buildName(dwi, "upsample"))

        b0Upsample = os.path.join(self.workingDir, os.path.basename(dwiUpsample).replace(self.get("prefix", 'dwi'), self.get("prefix", 'b0')))
        self.info(mriutil.extractFirstB0FromDwi(dwiUpsample, b0Upsample, bVals))
コード例 #3
0
ファイル: 05-correction.py プロジェクト: bpinsard/toad
    def __validateSizeAndDimension(self, *args):

        names = []
        dims = []
        sizes = []

        for source in args:
            if source:
                names.append(source)
                dimensions = mriutil.getMriDimensions(source)
                if len(dimensions) == 4:
                    dims.append([dimensions[0], dimensions[1], dimensions[2]])
                else:
                    dims.append(dimensions)
                    # sourceSize sanitization
                    sourceSize = mriutil.getMriVoxelSize(source)
                    try:
                        sourceSize = ["{:.1f}".format(float(val)) for val in sourceSize]
                    except ValueError:
                        self.error("Error during sourceSize sanitization")
                    sizes.append(sourceSize)

        if not dims[1:] == dims[:-1]:
            self.error("Dimension for each scale mismatch found between images: {}".format(", ".join(names)))

        if not sizes[1:] == sizes[:-1]:
            self.error("Voxel size mismatch found between images: {}".format(", ".join(names)))
コード例 #4
0
    def __validateSizeAndDimension(self, dwi, b0PA, b0AP):

        dwiDim   = mriutil.getMriDimensions(dwi)
        dwiVoxel = mriutil.getMriVoxelSize(dwi)
        b0PADim   = mriutil.getMriDimensions(b0PA)
        b0PAVoxel = mriutil.getMriVoxelSize(b0PA)
        b0APDim   = mriutil.getMriDimensions(b0AP)
        b0APVoxel = mriutil.getMriVoxelSize(b0AP)

        self.info("Look if {} and {} and {} have the same voxel size".format(dwi, b0PA, b0AP))
        if len(dwiVoxel) == len(b0PAVoxel) == len(b0APVoxel) == 3:
            for i in range(0,len(dwiVoxel)):
                if not (dwiVoxel[i] == b0PAVoxel[i] == b0APVoxel[i]):
                    self.error("Voxel size mismatch found at index {} for image {} {} {}".format(i, dwi, b0PA, b0AP))
        else:
            self.error("Found Voxel size inconsistency for image {} or  {} or {}".format(dwi, b0PA, b0AP))

        self.info("Look if {} and {} and {} have the same dimension for each scale".format(dwi, b0PA, b0AP))
        for i in range(0,3):
                if not (dwiDim[i]==b0PADim[i]==b0APDim[i]):
                    self.error("Dimensions mismatch found at index {} for image {} {} {}".format(i, dwi, b0PA, b0AP))
コード例 #5
0
ファイル: 15-snr.py プロジェクト: sbrambati/toad
    def implement(self):

        #Noise mask computation
        brainMask = self.getCorrectionImage('mask', 'corrected')
        noiseMask = self.__computeNoiseMask(brainMask)

        #Voxel Size of native dwi
        dwiNative = self.getPreparationImage('dwi')
        voxelSize = mriutil.getMriVoxelSize(dwiNative)

        #Corpus Callosum masks
        ccMask = self.getMaskingImage('aparc_aseg', ['253','mask'])
        ccMaskDownsample = self.buildName(ccMask, 'downsample')
        cmdString = "mri_convert -voxsize {} -rl {} --input_volume {} --output_volume {}"
        cmd = cmdString.format(" ".join(voxelSize), brainMask, ccMask, ccMaskDownsample)
        self.launchCommand(cmd)
コード例 #6
0
ファイル: 17-snr.py プロジェクト: kaurousseau/toad
    def implement(self):

        # Noise mask computation
        brainMask = self.getCorrectionImage("mask", "corrected")

        noiseMask = mriutil.computeNoiseMask(brainMask, self.buildName(brainMask, "noisemask"))

        # Voxel Size of native dwi
        dwiNative = self.getPreparationImage("dwi")
        voxelSize = mriutil.getMriVoxelSize(dwiNative)

        # Corpus Callosum masks
        ccMask = self.getMaskingImage("aparc_aseg", ["253", "mask"])
        ccMaskDownsample = self.buildName(ccMask, "downsample")
        cmdString = "mri_convert -voxsize {} -rl {} --input_volume {} --output_volume {}"
        cmd = cmdString.format(" ".join(voxelSize), brainMask, ccMask, ccMaskDownsample)
        self.launchCommand(cmd)
コード例 #7
0
    def implement(self):

        #Noise mask computation
        brainMask = self.getCorrectionImage('mask', 'corrected')

        noiseMask = mriutil.computeNoiseMask(
            brainMask, self.buildName(brainMask, 'noisemask'))

        #Voxel Size of native dwi
        dwiNative = self.getPreparationImage('dwi')
        voxelSize = mriutil.getMriVoxelSize(dwiNative)

        #Corpus Callosum masks
        ccMask = self.getMaskingImage('aparc_aseg', ['253', 'mask'])
        ccMaskDownsample = self.buildName(ccMask, 'downsample')
        cmdString = "mri_convert -voxsize {} -rl {} --input_volume {} --output_volume {}"
        cmd = cmdString.format(" ".join(voxelSize), brainMask, ccMask,
                               ccMaskDownsample)
        self.launchCommand(cmd)
コード例 #8
0
ファイル: 03-correction.py プロジェクト: inej/toad
    def __validateSizeAndDimension(self, *args):

        names = []
        dims = []
        sizes = []

        for source in args:
            if source:
                names.append(source)
                dimensions = mriutil.getMriDimensions(source)
                if len(dimensions) == 4:
                    dims.append([dimensions[0], dimensions[1], dimensions[2]])
                else:
                    dims.append(dimensions)
                    sizes.append(mriutil.getMriVoxelSize(source))

        if not dims[1:] == dims[:-1]:
            self.error("Dimension for each scale mismatch found between images: {}".format(", ".join(names)))

        if not sizes[1:] == sizes[:-1]:
            self.error("Voxel size mismatch found between images: {}".format(", ".join(names)))