How to use the histomicstk.cli.utils.disp_time_hms function in histomicstk

To help you get started, we’ve selected a few histomicstk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DigitalSlideArchive / HistomicsTK / histomicstk / cli / NucleiDetection / NucleiDetection.py View on Github external
process_whole_image = False

    #
    # Initiate Dask client
    #
    print('\n>> Creating Dask client ...\n')

    start_time = time.time()

    c = cli_utils.create_dask_client(args)

    print(c)

    dask_setup_time = time.time() - start_time
    print('Dask setup time = {}'.format(
        cli_utils.disp_time_hms(dask_setup_time)))

    #
    # Read Input Image
    #
    print('\n>> Reading input image ... \n')

    ts = large_image.getTileSource(args.inputImageFile)

    ts_metadata = ts.getMetadata()

    print(json.dumps(ts_metadata, indent=2))

    is_wsi = ts_metadata['magnification'] is not None

    #
    # Compute tissue/foreground mask at low-res for whole slide images
github DigitalSlideArchive / HistomicsTK / histomicstk / cli / NucleiDetection / NucleiDetection.py View on Github external
annot_fname = os.path.splitext(
        os.path.basename(args.outputNucleiAnnotationFile))[0]

    annotation = {
        "name":     annot_fname + '-nuclei-' + args.nuclei_annotation_format,
        "elements": nuclei_list
    }

    with open(args.outputNucleiAnnotationFile, 'w') as annotation_file:
        json.dump(annotation, annotation_file, indent=2, sort_keys=False)

    total_time_taken = time.time() - total_start_time

    print('Total analysis time = {}'.format(
        cli_utils.disp_time_hms(total_time_taken)))
github DigitalSlideArchive / HistomicsTK / histomicstk / cli / SuperpixelSegmentation / CreateDataset.py View on Github external
if is_wsi:

            #
            # Compute tissue/foreground mask at low-res for whole slide images
            #
            print('\n>> Computing tissue/foreground mask at low-res ...\n')

            start_time = time.time()

            im_fgnd_mask_lres, fgnd_seg_scale = \
                cli_utils.segment_wsi_foreground_at_low_res(ts)

            fgnd_time = time.time() - start_time

            print('low-res foreground mask computation time = {}'.format(
                cli_utils.disp_time_hms(fgnd_time)))

            it_kwargs = {
                'tile_size': {'width': args.analysis_tile_size},
                'scale': {'magnification': args.analysis_mag},
            }

            #
            # Compute foreground fraction of tiles in parallel using Dask
            #
            print('\n>> Computing foreground fraction of all tiles ...\n')

            start_time = time.time()

            num_tiles = \
                ts.getSingleTile(**it_kwargs)['iterator_range']['position']
github DigitalSlideArchive / HistomicsTK / histomicstk / cli / ComputeNucleiFeatures / ComputeNucleiFeatures.py View on Github external
nuclei_fdata = pd.DataFrame()

    if len(nuclei_annot_list) > 0:

        nuclei_fdata = pd.concat([
            fdata
            for annot_list, fdata in tile_result_list if fdata is not None],
            ignore_index=True
        )

    nuclei_detection_time = time.time() - start_time

    print('Number of nuclei = {}'.format(len(nuclei_annot_list)))
    print('Nuclei detection time = {}'.format(
        cli_utils.disp_time_hms(nuclei_detection_time)))

    #
    # Write annotation file
    #
    print('\n>> Writing annotation file ...\n')

    annot_fname = os.path.splitext(
        os.path.basename(args.outputNucleiAnnotationFile))[0]

    annotation = {
        "name": annot_fname + '-nuclei-' + args.nuclei_annotation_format,
        "elements": nuclei_annot_list
    }

    with open(args.outputNucleiAnnotationFile, 'w') as annotation_file:
        json.dump(annotation, annotation_file, indent=2, sort_keys=False)
github DigitalSlideArchive / HistomicsTK / histomicstk / cli / ComputeNucleiFeatures / ComputeNucleiFeatures.py View on Github external
else:

            tile_fgnd_frac_list = [1.0] * num_tiles

        num_fgnd_tiles = np.count_nonzero(
            tile_fgnd_frac_list >= args.min_fgnd_frac)

        percent_fgnd_tiles = 100.0 * num_fgnd_tiles / num_tiles

        fgnd_frac_comp_time = time.time() - start_time

        print('Number of foreground tiles = {0:d} ({1:2f}%%)'.format(
            num_fgnd_tiles, percent_fgnd_tiles))

        print('Tile foreground fraction computation time = {}'.format(
            cli_utils.disp_time_hms(fgnd_frac_comp_time)))

    #
    # Compute reinhard stats for color normalization
    #
    src_mu_lab = None
    src_sigma_lab = None

    if is_wsi and process_whole_image:

        print('\n>> Computing reinhard color normalization stats ...\n')

        start_time = time.time()

        src_mu_lab, src_sigma_lab = htk_cnorm.reinhard_stats(
            args.inputImageFile, 0.01, magnification=args.analysis_mag)
github DigitalSlideArchive / HistomicsTK / histomicstk / cli / SuperpixelSegmentation / CreateDataset.py View on Github external
num_fgnd_tiles, percent_fgnd_tiles))

            print('Tile foreground fraction computation time = {}'.format(
                cli_utils.disp_time_hms(fgnd_frac_comp_time)))

            print('\n>> Computing reinhard color normalization stats ...\n')

            start_time = time.time()

            src_mu_lab, src_sigma_lab = htk_cnorm.reinhard_stats(
                img_paths[i], 0.01, magnification=args.analysis_mag)

            rstats_time = time.time() - start_time

            print('Reinhard stats computation time = {}'.format(
                cli_utils.disp_time_hms(rstats_time)))

            #
            # Detect boundary and centroids in parallel using Dask
            #
            print('\n>> Detecting boundary and centroids ...\n')

            start_time = time.time()

            tile_result_list = []

            for tile in ts.tileIterator(**it_kwargs):

                tile_position = tile['tile_position']['position']

                if tile_fgnd_frac_list[tile_position] <= args.min_fgnd_frac:
                    continue
github DigitalSlideArchive / HistomicsTK / histomicstk / cli / ComputeNucleiFeatures / ComputeNucleiFeatures.py View on Github external
src_mu_lab = None
    src_sigma_lab = None

    if is_wsi and process_whole_image:

        print('\n>> Computing reinhard color normalization stats ...\n')

        start_time = time.time()

        src_mu_lab, src_sigma_lab = htk_cnorm.reinhard_stats(
            args.inputImageFile, 0.01, magnification=args.analysis_mag)

        rstats_time = time.time() - start_time

        print('Reinhard stats computation time = {}'.format(
            cli_utils.disp_time_hms(rstats_time)))

    #
    # Detect and compute nuclei features in parallel using Dask
    #
    print('\n>> Detecting nuclei and computing features ...\n')

    start_time = time.time()

    tile_result_list = []

    for tile in ts.tileIterator(**it_kwargs):

        tile_position = tile['tile_position']['position']

        if is_wsi and tile_fgnd_frac_list[tile_position] <= args.min_fgnd_frac:
            continue