Exemplo n.º 1
0
def main():  # pragma: no cover

    #    import ipdb; ipdb.set_trace() # BREAKPOINT
    try:
        ch, fh = logger_init()
        cfg = lisa_config_init()
        args = parser_init(cfg)

        # rint args["arg"]
        oseg_argspec_keys = config.get_function_keys(
            OrganSegmentation.__init__)

        if args["debug"]:
            ch.setLevel(logging.DEBUG)
            args["debug_mode"] = True

        if args["iparams"] is not None:
            params = misc.obj_from_file(args["iparams"], filetype='pickle')

        else:
            params = config.subdict(args, oseg_argspec_keys)

        logger.debug('params ' + str(params))
        oseg = OrganSegmentation(**params)

        if args["no_interactivity"]:
            oseg.ninteractivity()
            oseg.save_outputs()
        else:
            # mport_gui()
            from lisaWindow import OrganSegmentationWindow
            from PyQt4.QtGui import QApplication
            app = QApplication(sys.argv)
            oseg_w = OrganSegmentationWindow(oseg)  # noqa
#    import pdb; pdb.set_trace()
            sys.exit(app.exec_())

    except Exception as e:
        # mport exceptionProcessing
        exceptionProcessing.reportException(e)
        print traceback.format_exc()
Exemplo n.º 2
0
def main():

    #logger = logging.getLogger(__name__)
    logger = logging.getLogger()

    logger.setLevel(logging.WARNING)
    ch = logging.StreamHandler()
    logger.addHandler(ch)

    #logger.debug('input params')

    print 'version: ', qmisc.getVersionString()
###
# Configuration is has three sources:
#  * Default function values
#  * Config file 'organ_segmentation.config' in directory with application
#  * Config file 'organ_segmentation.config' in output data directory
#
# It is read in this order so the last one has highest priority

###
## read confguraton from file, use default values from OrganSegmentation
    cfgplus = {
        'datapath': None,
        'viewermax': 300,
        'viewermin': -100,
        'output_datapath': os.path.expanduser("~/lisa_data"),
        'lisa_operator_identifier': "",
        'experiment_caption': ''
    }

    cfg = config.get_default_function_config(OrganSegmentation.__init__)
    cfg.update(cfgplus)
    # now is in cfg default values

    cfg = config.get_config("organ_segmentation.config", cfg)
# read user defined config in user data
    cfg = config.get_config(
        os.path.join(cfg['output_datapath'], "organ_segmentation.config"),
        cfg
    )

    # input parser
    parser = argparse.ArgumentParser(
        description='Segment vessels from liver \n\
                \npython organ_segmentation.py\n\
                \npython organ_segmentation.py -mroi -vs 0.6')
    parser.add_argument('-dd', '--datapath',
                        default=cfg["datapath"],
                        help='path to data dir')
    parser.add_argument('-d', '--debug', action='store_true',
                        help='run in debug mode')
    parser.add_argument(
        '-vs', '--working_voxelsize_mm',
        default=cfg["working_voxelsize_mm"],
        type=eval,  # type=str,
        help='Insert working voxelsize. It can be number or \
        array of three numbers. It is possible use original \n \
        resolution or half of original resolution. \n \
        -vs 3 \n \
        -vs [3,3,5] \n \
        -vs orig \n \
        -vs orig*2 \n \
        -vs orig*4 \n \
        '
    )
    parser.add_argument('-mroi', '--manualroi', action='store_true',
                        help='manual crop before data processing',
                        default=cfg["manualroi"])

    parser.add_argument('-op', '--output_datapath',
                        default=cfg["output_datapath"],
                        help='path for output data')

    parser.add_argument('-ol', '--output_label', default=1,
                        help='label for segmented data')
    parser.add_argument(
        '--slab',
        default=cfg["slab"],
        type=eval,
        help='labels for segmentation,\
            example -slab "{\'liver\':1, \'lesions\':6}"')
    parser.add_argument(
        '-acr', '--autocrop',
        help='automatic crop after data processing',
        default=cfg["autocrop"])
    parser.add_argument(
        '-iparams', '--iparams',
        default=None,
        help='filename of ipars file with stored interactivity')
    parser.add_argument(
        '-sp', '--segparams', type=eval,
        default=cfg["segparams"],
        help='params for segmentation,\
            example -sp "{\'pairwise_alpha_per_mm2\':90}"')
    parser.add_argument(
        '-tx', '--texture_analysis', action='store_true',
        help='run with texture analysis')
    parser.add_argument('-exd', '--exampledata', action='store_true',
                        help='run unittest')
    parser.add_argument('-ed', '--edit_data', action='store_true',
                        help='Run data editor')
    parser.add_argument(
        '-vmax', '--viewermax', type=eval,  # type=int,
        help='Maximum of viewer window, set None for automatic maximum.',
        default=cfg["viewermax"])
    parser.add_argument(
        '-vmin', '--viewermin', type=eval,  # type=int,
        help='Minimum of viewer window, set None for automatic minimum.',
        default=cfg["viewermin"])
    parser.add_argument(
        '-so', '--show_output', action='store_true',
        help='Show output data in viewer')
    parser.add_argument('-a', '--arg', nargs='+', type=float)
    parser.add_argument(
        '-ec', '--experiment_caption', type=str,  # type=int,
        help='Short caption of experiment. No special characters.',
        default=cfg["experiment_caption"])
    parser.add_argument(
        '-oi', '--lisa_operator_identifier', type=str,  # type=int,
        help='Identifier of Lisa operator.',
        default=cfg["experiment_caption"])
    parser.add_argument(
        '-ss',
        '--segmentation_smoothing',
        action='store_true',
        help='Smoothing of output segmentation',
        default=cfg["segmentation_smoothing"]
    )
    args_obj = parser.parse_args()
    args = vars(args_obj)
    #print args["arg"]
    oseg_argspec_keys = config.get_function_keys(OrganSegmentation.__init__)

    # voxelsize_mm can be number or array
    #if args.voxelsize_mm != 'orig':
#TODO easy way to set half of resolution
#    if isinstance(args["working_voxelsize_mm"], numbers.Number)
#        if args["working_voxelsize_mm"] == -1:
#            args["working_voxelsize_mm"] = 'orig'
## todo and so on
#    if not args["working_voxelsize_mm"].startswith('orig'):
#        #import pdb; pdb.set_trace()
#        args["working_voxelsize_mm"] = eval(args["working_voxelsize_mm"])

    #
    #args["segparams"] = eval(args["segparams"])
    #args["slab"] = eval(args["slab"])

    #args["viewermin"] = eval(args["viewermin"])
    #args["viewermax"] = eval(args["viewermax"])

    if args["debug"]:
        logger.setLevel(logging.DEBUG)

    if args["exampledata"]:

        args["datapath"] = '../sample_data/\
                matlab/examples/sample_data/DICOM/digest_article/'

    if args["iparams"] is not None:
        iparams = misc.obj_from_file(args["iparams"], filetype='pickle')
        oseg = OrganSegmentation(**iparams)

    else:
    #else:
    #dcm_read_from_dir('/home/mjirik/data/medical/data_orig/46328096/')
        #data3d, metadata = dcmreaddata.dcm_read_from_dir()
        data3d, metadata, qt_app = readData3d(args["datapath"])
        args['datapath'] = metadata['datadir']

        oseg_params = config.subdict(args, oseg_argspec_keys)
        oseg_params["data3d"] = data3d
        oseg_params["metadata"] = metadata
        oseg_params['qt_app'] = qt_app
        oseg = OrganSegmentation(**oseg_params)

    oseg.interactivity(args["viewermin"], args["viewermax"])

    #igc = pycut.ImageGraphCut(data3d, zoom = 0.5)
    #igc.interactivity()

    #igc.make_gc()
    #igc.show_segmentation()
    # volume
    #volume_mm3 = np.sum(oseg.segmentation > 0) * np.prod(oseg.voxelsize_mm)

    audiosupport.beep()
    print(
        "Volume " +
        str(oseg.get_segmented_volume_size_mm3() / 1000000.0) + ' [l]')
    #pyed = py3DSeedEditor.py3DSeedEditor(oseg.data3d, contour =
    # oseg.segmentation)
    #pyed.show()
    print("Total time: " + str(oseg.processing_time))

    if args["show_output"]:
        oseg.show_output()

    #print savestring
    save_outputs(args, oseg, qt_app)
#    import pdb; pdb.set_trace()
    return