Beispiel #1
0
    def ImportMedicalImages(self, directory, gui=True):
        patients_groups = dcm.GetDicomGroups(directory)
        name = directory.rpartition('\\')[-1].split('.')
        print("patients: ", patients_groups)

        if len(patients_groups):
            # OPTION 1: DICOM
            group = dcm.SelectLargerDicomGroup(patients_groups)
            matrix, matrix_filename, dicom = self.OpenDicomGroup(group,
                                                                 0, [0, 0],
                                                                 gui=gui)
            self.CreateDicomProject(dicom, matrix, matrix_filename)
        else:
            # OPTION 2: NIfTI, Analyze or PAR/REC
            if name[-1] == 'gz':
                name[1] = 'nii.gz'

            suptype = ('hdr', 'nii', 'nii.gz', 'par')
            filetype = name[1].lower()

            if filetype in suptype:
                group = oth.ReadOthers(directory)
            else:
                utils.debug("No medical images found on given directory")
                return

            matrix, matrix_filename = self.OpenOtherFiles(group)
            self.CreateOtherProject(str(name[0]), matrix, matrix_filename)
            # OPTION 4: Nothing...

        self.LoadProject()
        Publisher.sendMessage("Enable state project", state=True)
Beispiel #2
0
def use_cmd_optargs(options, args):
    # If debug argument...
    if options.debug:
        Publisher.subscribe(print_events, Publisher.ALL_TOPICS)
        session = ses.Session()
        session.debug = 1

    # If import DICOM argument...
    if options.dicom_dir:
        import_dir = options.dicom_dir
        Publisher.sendMessage('Import directory', {
            'directory': import_dir,
            'gui': not options.no_gui
        })

        if options.save:
            Publisher.sendMessage('Save project',
                                  os.path.abspath(options.save))
            exit(0)

        check_for_export(options)

        return True
    elif options.import_all:
        import invesalius.reader.dicom_reader as dcm
        for patient in dcm.GetDicomGroups(options.import_all):
            for group in patient.GetGroups():
                Publisher.sendMessage('Import group', {
                    'group': group,
                    'gui': not options.no_gui
                })
                check_for_export(options,
                                 suffix=group.title,
                                 remove_surfaces=False)
                Publisher.sendMessage('Remove masks', [0])
        return True

    # Check if there is a file path somewhere in what the user wrote
    # In case there is, try opening as it was a inv3
    else:
        for arg in reversed(args):

            file = utils.decode(arg, FS_ENCODE)
            if os.path.isfile(file):
                path = os.path.abspath(file)
                Publisher.sendMessage('Open project', path)
                check_for_export(options)
                return True

            file = utils.decode(arg, sys.stdin.encoding)
            if os.path.isfile(file):
                path = os.path.abspath(file)
                Publisher.sendMessage('Open project', path)
                check_for_export(options)
                return True

    return False
Beispiel #3
0
def use_cmd_optargs(options, args):
    # If import DICOM argument...
    if options.dicom_dir:
        import_dir = options.dicom_dir
        Publisher.sendMessage('Import directory',
                              directory=import_dir,
                              use_gui=not options.no_gui)

        if options.save:
            Publisher.sendMessage('Save project',
                                  filepath=os.path.abspath(options.save))
            exit(0)

        check_for_export(options)

        return True
    elif options.import_folder:
        Publisher.sendMessage('Import folder', folder=options.import_folder)
        if options.save:
            Publisher.sendMessage('Save project',
                                  filepath=os.path.abspath(options.save))
            exit(0)
        check_for_export(options)

    elif options.import_all:
        import invesalius.reader.dicom_reader as dcm
        for patient in dcm.GetDicomGroups(options.import_all):
            for group in patient.GetGroups():
                Publisher.sendMessage('Import group',
                                      group=group,
                                      use_gui=not options.no_gui)
                check_for_export(options,
                                 suffix=group.title,
                                 remove_surfaces=False)
                Publisher.sendMessage('Remove masks', mask_indexes=(0, ))
        return True

    # Check if there is a file path somewhere in what the user wrote
    # In case there is, try opening as it was a inv3
    else:
        for arg in reversed(args):

            file = utils.decode(arg, FS_ENCODE)
            if os.path.isfile(file):
                path = os.path.abspath(file)
                Publisher.sendMessage('Open project', filepath=path)
                check_for_export(options)
                return True

            file = utils.decode(arg, sys.stdin.encoding)
            if os.path.isfile(file):
                path = os.path.abspath(file)
                Publisher.sendMessage('Open project', filepath=path)
                check_for_export(options)
                return True

    return False
Beispiel #4
0
 def ImportMedicalImages(self, directory):
     # OPTION 1: DICOM?
     patients_groups = dcm.GetDicomGroups(directory)
     if len(patients_groups):
         group = dcm.SelectLargerDicomGroup(patients_groups)
         matrix, matrix_filename, dicom = self.OpenDicomGroup(group,
                                                              0, [0, 0],
                                                              gui=True)
         self.CreateDicomProject(dicom, matrix, matrix_filename)
     # OPTION 2: ANALYZE?
     else:
         imagedata = analyze.ReadDirectory(directory)
         if imagedata:
             self.CreateAnalyzeProject(imagedata)
         # OPTION 3: Nothing...
         else:
             utils.debug("No medical images found on given directory")
             return
     self.LoadProject()
     Publisher.sendMessage("Enable state project", True)