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)
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)
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)
def implement(self): dwi = self.getPreparationImage("dwi") bVals = self.getPreparationImage('grad', None, 'bvals') norm= self.getParcellationImage('norm') parcellationMask = self.getParcellationImage('mask') b0 = os.path.join(self.workingDir, os.path.basename(dwi).replace(self.get("prefix", 'dwi'), self.get("prefix", 'b0'))) self.info(mriutil.extractFirstB0FromDwi(dwi, b0, bVals)) self.info("create a suitable mask for the dwi") extraArgs = "" if self.get("parcellation", "intrasubject"): extraArgs += " -usesqform -dof 6" mask = mriutil.computeDwiMaskFromFreesurfer(b0, norm, parcellationMask, self.buildName(parcellationMask, 'resample'), extraArgs) target = self.buildName(dwi, "denoise") if self.get("algorithm") == "nlmeans": self.algorithm = "nlmeans" dwiImage = nibabel.load(dwi) dwiData = dwiImage.get_data() if self.get('number_array_coil') == "32": noiseMask = mriutil.computeNoiseMask(mask, self.buildName(mask, 'noise_mask')) noiseMaskImage = nibabel.load(noiseMask) noiseMaskData = noiseMaskImage.get_data() sigma = numpy.std(dwiData[noiseMaskData > 0]) self.info("sigma value that will be apply into nlmeans = {}".format(sigma)) denoisingData = dipy.denoise.nlmeans.nlmeans(dwiData, sigma) else: self.sigmaVector, sigma, piesnoNoiseMask = self.__computeSigmaAndNoiseMask(dwiData) self.info("sigma value that will be apply into nlmeans = {}".format(sigma)) denoisingData = dipy.denoise.nlmeans.nlmeans(dwiData, sigma) nibabel.save(nibabel.Nifti1Image(piesnoNoiseMask.astype(numpy.float32),dwiImage.get_affine()), self.buildName(target, "piesno_noise_mask")) nibabel.save(nibabel.Nifti1Image(denoisingData.astype(numpy.float32), dwiImage.get_affine()), target) elif self.get('general', 'matlab_available'): dwiUncompress = self.uncompressImage(dwi) tmp = self.buildName(dwiUncompress, "tmp", 'nii') scriptName = self.__createMatlabScript(dwiUncompress, tmp) self.__launchMatlabExecution(scriptName) self.info("compressing {} image".format(tmp)) tmpCompress = util.gzip(tmp) self.rename(tmpCompress, target) if self.get("cleanup"): self.info("Removing redundant image {}".format(dwiUncompress)) os.remove(dwiUncompress) else: self.matlabWarning = True self.warning("Algorithm {} is set but matlab is not available for this server.\n" "Please configure matlab or set denoising algorithm to nlmeans or none" .format(self.get("algorithm")))
def implement(self): dwi = self.getPreparationImage("dwi") bVals = self.getPreparationImage('grad', None, 'bvals') norm= self.getParcellationImage('norm') parcellationMask = self.getParcellationImage('mask') b0 = os.path.join(self.workingDir, os.path.basename(dwi).replace(self.get("prefix", 'dwi'), self.get("prefix", 'b0'))) self.info(mriutil.extractFirstB0FromDwi(dwi, b0, bVals)) self.info("create a suitable mask for the dwi") extraArgs = " -dof 6 " if self.get("methodology", "intrasession"): extraArgs += " -usesqform " mask = mriutil.computeDwiMaskFromFreesurfer(b0, norm, parcellationMask, self.buildName(parcellationMask, 'resample'), extraArgs) target = self.buildName(dwi, "denoise") if self.get("algorithm") == "mp-pca": targetNoise = self.buildName(dwi, "noise") self.algorithm = "mp-pca" #cmd = "dwidenoise {} {} -mask {} -noise {} -extent {} -nthreads {} -quiet".format(dwi, target, mask, targetNoise, self.get('extent'), self.getNTreadsMrtrix()) cmd = "dwidenoise {} {} -noise {} -extent {} -nthreads {} -quiet".format(dwi, target, targetNoise, self.get('extent'), self.getNTreadsMrtrix()) self.launchCommand(cmd) elif self.get("algorithm") == "nlmeans": self.algorithm = "nlmeans" dwiImage = nibabel.load(dwi) dwiData = dwiImage.get_data() #if self.get('number_array_coil') == "32": noiseMask = mriutil.computeNoiseMask(mask, self.buildName(mask, 'noise_mask')) noiseMaskImage = nibabel.load(noiseMask) noiseMaskData = noiseMaskImage.get_data() sigma = numpy.std(dwiData[noiseMaskData > 0]) self.info("sigma value that will be apply into nlmeans = {}".format(sigma)) denoisingData = dipy.denoise.nlmeans.nlmeans(dwiData, sigma) #else: #self.sigmaVector, sigma, piesnoNoiseMask = self.__computeSigmaAndNoiseMask(dwiData) #self.info("sigma value that will be apply into nlmeans = {}".format(sigma)) #denoisingData = dipy.denoise.nlmeans.nlmeans(dwiData, sigma) #nibabel.save(nibabel.Nifti1Image(piesnoNoiseMask.astype(numpy.float32),dwiImage.get_affine()), self.buildName(target, "piesno_noise_mask")) nibabel.save(nibabel.Nifti1Image(denoisingData.astype(numpy.float32), dwiImage.get_affine()), target) elif self.get('general', 'matlab_available'): dwiUncompress = self.uncompressImage(dwi) tmp = self.buildName(dwiUncompress, "tmp", 'nii') scriptName = self.__createMatlabScript(dwiUncompress, tmp) self.__launchMatlabExecution(scriptName) self.info("compressing {} image".format(tmp)) tmpCompress = util.gzip(tmp) self.rename(tmpCompress, target) if self.get("cleanup"): self.info("Removing redundant image {}".format(dwiUncompress)) os.remove(dwiUncompress) else: self.matlabWarning = True self.warning("Algorithm {} is set but matlab is not available for this server.\n" "Please configure matlab or set denoising algorithm to nlmeans or none" .format(self.get("algorithm")))