Beispiel #1
0
def  BrainExtractFast(input,output):
    '''
    :param input:
    :param output:
    :return:
    use FSL . bet2  , faster than HD-BET
    '''

    # is the input is dir? or file?
    import subprocess
    images = []
    outputImages = []
    if os.path.isdir(input):
        if not os.path.exists(output):
            os.mkdir(output)
        images = utils.checkDir(input)
        if(len(images) == 0):
            print("there is no images in the input dir")
            return
        for image in images:
            outputImages.append(os.path.join(output,"Bet_"+os.path.basename(image)))
    else:
        images.append(input)
        outputImages.append(output)
    exPath = os.path.join(setting.path, "bet", "bet2.exe")

    for image,outputImage in zip(images,outputImages):
        task = subprocess.Popen('%s %s %s' % (exPath, image, outputImage), shell=True,
                            stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        msg = ''
        for line in task.stdout.readlines():
            msg += line.decode("gb2312")
        status = task.wait()
        print(msg)
Beispiel #2
0
 def runCal(self):
     from Core.utils import checkFile, checkDir
     self.pbar.setValue(1)
     if (self.fileRadiobtn.isChecked()):
         if checkFile(self.imageFile) == 1:
             QMessageBox.information(self, "Warning",
                                     "The image path is not valid!",
                                     QMessageBox.Yes)
             return
         self.thread = RunThread(self.imageFile,
                                 self.maskFile,
                                 self.fileName,
                                 type='singleFile')
     else:
         if len(checkDir(self.directory1)) == 0:
             QMessageBox.information(self, "Warning",
                                     "The directory path is not valid!",
                                     QMessageBox.Yes)
             return
         self.thread = RunThread(self.directory1,
                                 self.directory2,
                                 self.fileName,
                                 type="dir")
     self.thread.start()
     # self.thread2 = procThread()
     # self.thread2.start()
     self.thread.trigger.connect(self.process)
     self.btnStart.setText("Calculating...")
     self.btnStart.setDisabled(True)
Beispiel #3
0
 def cal(self):
     from Core.utils import checkFile, checkDir, checkOutputDir, checkOutputFile
     if ((not self.CheckNorm) and (not self.CheckBFC)):
         QMessageBox.information(self, "Warning",
                                 "Please Choose at least one function!",
                                 QMessageBox.Yes)
         return
     if self.RadioSingle.isChecked():
         if checkFile(self.imageFile) == 1 or checkOutputFile(
                 self.outputPath) == 1:
             QMessageBox.information(self, "Warning",
                                     "The image path is not valid!",
                                     QMessageBox.Yes)
             return
     else:
         if len(checkDir(self.imageFile)) == 0 or checkOutputDir(
                 self.outputPath) == 1:
             QMessageBox.information(self, "Warning",
                                     "The image path is not valid!",
                                     QMessageBox.Yes)
             return
     self.thread = calThread(self.imageFile, self.outputPath,
                             self.CheckBFC.isChecked(),
                             self.CheckNorm.isChecked(),
                             self.RadioSingle.isChecked())
     self.thread.signal.connect(self.process)
     self.thread.start()
     self.BtnStart.setDisabled(True)
     self.BtnStart.setText("Calculating...")
Beispiel #4
0
def segment(filename_input, directory_output, Type=False):
    '''
    :param filename_input: input dir or filename
    :param directory_output: output dir name
    :param Type: True ,use dir mode / False use file mode
    :return:
    '''
    inipath = setting.LiviaNet_iniPath
    modelname = setting.LiviaNet_modelPath
    print(inipath)
    print(modelname)
    print(filename_input)
    filepath = filename_input

    iniFile = resini(inipath)

    # True THE Whole dir
    try:
        if Type:
            num = str([i for i in range(len(os.listdir(filename_input)))])
            iniFile.write(filepath, "imagesFolder")
            images = checkDir(filepath)
            for image in images:
                idata = nib.load(image)
                data = idata.get_fdata()
                affine = idata.affine
                data = (data - np.mean(data.flatten())) / np.std(
                    data.flatten())

                nib.save(nib.Nifti1Image(data, affine).to_filename(image))
        else:

            idata = nib.load(filepath)
            data = idata.get_fdata()
            affine = idata.affine

            data = (data - np.mean(data.flatten())) / np.std(data.flatten())
            nib.save(nib.Nifti1Image(data, affine), filepath)

            getNum = lambda file_path, file_name: os.listdir(file_path).index(
                file_name)
            num = [
                getNum(os.path.dirname(filepath), os.path.basename(filepath))
            ]  # 获得文件的索引值
            iniFile.write(os.path.dirname(filepath), "imagesFolder")
        # resindex = resini(inipath)  # 实例化resindex
        iniFile.write(str(num),
                      "indexestosegment")  # 将 indexestosegment 写入ini文件
        roiPath = os.path.join(path, "hippoSeg", "roi")
        iniFile.write(roiPath, "roifolder")
        net.startTesting(modelname, inipath, directory_output)
    except Exception as e:
        print(e)
        return 1
    return 0
 def cal(self):
     if self.RadioSingle.isChecked():
         if checkFile(self.imageFile) == 1 or checkOutputFile(self.outputPath) == 1:
             QMessageBox.information(self, "Warning", "The image path is not valid!", QMessageBox.Yes)
             return
     else:
         if len(checkDir(self.imageFile)) == 0 or checkOutputDir(self.outputPath) == 1:
             QMessageBox.information(self, "Warning", "The image path is not valid!", QMessageBox.Yes)
             return
     if((self.imageFile is None) and (self.outputPath is None)):
         QMessageBox.information(self, "Warning", "Please Choose the path!", QMessageBox.Yes)
         return
     self.thread = calThread(self.imageFile, self.outputPath,self.RadioSingle.isChecked())
     self.thread.signal.connect(self.process)
     self.thread.start()
     self.BtnStart.setDisabled(True)
     self.BtnStart.setText("Calculating...")
Beispiel #6
0
 def cal(self):
     '''
     这里hd-bet内部自动会判断输入的是文件夹/文件,故没有判断
     :return:
     '''
     from Core.utils import checkDir,checkFile,checkOutputFile,checkOutputDir
     if self.RadioSingle.isChecked():
         if (checkFile(self.imageFile) == 1 or checkOutputFile(self.outputPath) == 1):
             QMessageBox.information(self, "Warning", "The image path is not valid!", QMessageBox.Yes)
             return
     else:
         if (len(checkDir(self.imageFile)) == 0 or checkOutputDir(self.outputPath) == 1):
             QMessageBox.information(self, "Warning", "The image path is not valid!", QMessageBox.Yes)
             return
     self.thread = calThread(self.imageFile,self.outputPath,self.RadioFast.isChecked())
     self.thread.signal.connect(self.process)
     self.thread.start()
     self.BtnStart.setDisabled(True)
     self.BtnStart.setText("Calculating...")
 def slot_run0(self):  # 避免UI堵塞,开启新线程
     # self.pb = ProgressBar()     # 进度条显示
     # self.pb.show()
     from Core.utils import checkDir, checkFile
     if self.ui.RadioBtn_Dir.isChecked():
         if len(checkDir(self.filename_input)) == 0:
             QMessageBox.information(self, "Warning",
                                     "The directory path is not valid!",
                                     QMessageBox.Yes)
             return
     else:
         if checkFile(self.filename_input) == 1:
             QMessageBox.information(self, "Warning",
                                     "The image path is not valid!",
                                     QMessageBox.Yes)
             return
     self.ui.run_pushButton.setDisabled(True)
     self.thread = RunThread(self.filename_input,
                             self.directory_output,
                             Type=self.ui.RadioBtn_Dir.isChecked())
     self.thread.trigger.connect(self.process)
     self.thread.start()
 def run(self):
     if (self.refImage == None):
         self.refImage = ""
     if (self.type == 0):
         self.signal.emit(0.5)
         p = registration(flo=self.image,
                          res=self.resImage,
                          ref=self.refImage)
         self.signal.emit(1)
     #batch mode
     else:
         self.signal.emit(0.01)
         images = checkDir(self.image)
         i = 1
         for image in images:
             registration(flo=image,
                          res=os.path.join(self.resImage,
                                           "Reg" + os.path.basename(image)),
                          ref=self.refImage)
             self.signal.emit(i / len(images))
             i += 1
         self.signal.emit(1)
Beispiel #9
0
    def Cal(self):

        from Core.utils import checkFile, checkDir
        if self.RdioSingleFile.isChecked():
            if checkFile(self.Image) == 1:
                QMessageBox.information(self, "Warning",
                                        "The image path is not valid!",
                                        QMessageBox.Yes)
                return
            self.thread = calculate(self.Image, self.RefImage, self.ResImage)
        else:
            if len(checkDir(self.directory1)) == 0:
                QMessageBox.information(self, "Warning",
                                        "The directory path is not valid!",
                                        QMessageBox.Yes)
                return
            self.thread = calculate(self.directory1,
                                    self.RefImage,
                                    self.directory2,
                                    type=1)
        self.BtnStart.setDisabled(True)
        self.thread.start()
        self.thread.signal.connect(self.process)
Beispiel #10
0
 def calData(self):
     from Core.utils import checkDir,checkFile
     if len(checkDir(self.brainDIR)) == 0:
         QMessageBox.information(self, "Warning", "The image path is not valid!", QMessageBox.Yes)
         return
     brains = os.listdir(self.brainDIR)
     wmPath = ""
     gmPath =""
     csfPath=""
     for brain in brains:
         if(brain.find('wm')!=-1):
             wmPath = os.path.join(self.brainDIR,brain)
         elif(brain.find("csf")!=-1):
             csfPath = os.path.join(self.brainDIR,brain)
         elif(brain.find("gm")!=-1):
             gmPath = os.path.join(self.brainDIR,brain)
     if(wmPath == "" or gmPath == "" or csfPath== ""):
         QMessageBox.information(self, "Warning", "The brain segmentation path is not valid!", QMessageBox.Yes)
         return
     self.thread = calThread(self.FeaturePath,wmPath,gmPath,csfPath,self.HippoPath,self.imageFile,self.outputPath)
     self.thread.signal.connect(self.precess)
     self.thread.start()
     self.BtnStart.setDisabled(True)