How to use the histomicstk.cli.utils 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
if len(args.analysis_roi) != 4:
        raise ValueError('Analysis ROI must be a vector of 4 elements.')

    if np.all(np.array(args.analysis_roi) == -1):
        process_whole_image = True
    else:
        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()
github DigitalSlideArchive / HistomicsTK / histomicstk / cli / SeparateStainsXuSnmf / SeparateStainsXuSnmf.py View on Github external
def main(args):
    args = utils.splitArgs(args)
    args.snmf.I_0 = numpy.array(args.snmf.I_0)

    print(">> Starting Dask cluster and sampling pixels")
    utils.create_dask_client(args.dask)
    sample = utils.sample_pixels(args.sample)

    # Create stain matrix
    print('>> Creating stain matrix')

    args.snmf.w_init = utils.get_stain_matrix(args.stains, 2)

    print(args.snmf.w_init)

    # Perform color deconvolution
    print('>> Performing color deconvolution')

    w_est = htk_cdeconv.rgb_separate_stains_xu_snmf(sample.T, **vars(args.snmf))
    w_est = htk_cdeconv.complement_stain_matrix(w_est)

    with open(args.returnParameterFile, 'w') as f:
github DigitalSlideArchive / HistomicsTK / histomicstk / cli / ComputeNucleiFeatures / ComputeNucleiFeatures.py View on Github external
feature_file_format = os.path.splitext(args.outputNucleiFeatureFile)[1]

    if np.all(np.array(args.analysis_roi) == -1):
        process_whole_image = True
    else:
        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 = {} seconds'.format(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))
github DigitalSlideArchive / HistomicsTK / histomicstk / cli / BackgroundIntensity / BackgroundIntensity.py View on Github external
def main(args):
    other_args = set(['returnParameterFile', 'scheduler'])
    kwargs = {k: v for k, v in vars(args).items()
              if k not in other_args}
    # Allow (some) default parameters to work.  Assume certain values
    # are not valid.
    for k in 'sample_fraction', 'sample_approximate_total':
        if kwargs[k] == -1:
            del kwargs[k]

    utils.create_dask_client(args)
    I_0 = background_intensity(**kwargs)
    with open(args.returnParameterFile, 'w') as f:
        f.write('BackgroundIntensity = ' + ','.join(map(str, I_0)) + '\n')
github DigitalSlideArchive / HistomicsTK / histomicstk / cli / SeparateStainsMacenkoPCA / SeparateStainsMacenkoPCA.py View on Github external
def main(args):
    args = utils.splitArgs(args)
    args.macenko.I_0 = numpy.array(args.macenko.I_0)

    utils.create_dask_client(args.dask)
    sample = utils.sample_pixels(args.sample)
    stain_matrix = rgb_separate_stains_macenko_pca(sample.T, **vars(args.macenko))
    with open(args.returnParameterFile, 'w') as f:
        for i, stain in enumerate(stain_matrix.T):
            f.write('stainColor_{} = {}\n'.format(i+1, ','.join(map(str, stain))))
github DigitalSlideArchive / HistomicsTK / histomicstk / cli / ComputeNucleiFeatures / ComputeNucleiFeatures.py View on Github external
#
    # Compute tissue/foreground mask at low-res for whole slide images
    #
    if is_wsi and process_whole_image:

        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)))

    #
    # Compute foreground fraction of tiles in parallel using Dask
    #
    tile_fgnd_frac_list = [1.0]

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

    if not process_whole_image:

        it_kwargs['region'] = {
            'left':   args.analysis_roi[0],
            'top':    args.analysis_roi[1],
github DigitalSlideArchive / HistomicsTK / histomicstk / cli / SuperpixelSegmentation / CreateDataset.py View on Github external
for j in range(len(x_centroids)):
                boundary_out.write("%s\t" % slide_name)
                boundary_out.write("%.1f\t" % x_centroids[j])
                boundary_out.write("%.1f\t" % y_centroids[j])

                for k in range(len(x_boundaries[j])):
                    boundary_out.write(
                        "%d,%d " % (x_boundaries[j][k], y_boundaries[j][k]))

                boundary_out.write("\n")

            boundary_centroids_detection_time = time.time() - start_time

            print('Boundary and centroids detection time = {}'.format(
                cli_utils.disp_time_hms(boundary_centroids_detection_time)))

            #
            # Compute tissue/foreground mask at high-res for whole slide images
            #
            print('\n>> Computing foreground fraction of all tiles ...\n')

            it_kwargs = {
                'tile_size': {'width': args.superpixel_tile_size},
                'scale': {'magnification': args.superpixel_mag},
            }

            start_time = time.time()

            num_tiles = \
                ts.getSingleTile(**it_kwargs)['iterator_range']['position']