Пример #1
0
def main( ws_filename, label_filename, output_filename,

          thr_low, thr_high, thr_inc,

          calc_rfs=True, calc_re=True,
          calc_vifs=True, calc_vi=True,

          rel2d=False,
          foreground_restriction=False,
          split0=True,

          other=None):


    print("Reading data...")
    ws_seg, dend_pairs, dend_values = io_utils.import_ws_file( ws_filename )
    label_seg = io_utils.import_file( label_filename )
    assert ws_seg.shape == label_seg.shape


    thresholds = np.arange(thr_low, thr_high, thr_inc)

    prep = utils.parse_fns( utils.prep_fns,
                            [rel2d, foreground_restriction] )
    ws_seg, label_seg = utils.run_preprocessing( ws_seg, label_seg, prep )


    om = utils.calc_overlap_matrix( ws_seg, label_seg, split0 )


    metrics = utils.parse_fns( utils.metric_fns,
                               [calc_rfs,calc_re,
                                calc_vifs,calc_vi] )

    results = init_results( metrics, len(thresholds) )
    #descending threshold to allow incremental merging
    for i in range(thresholds.size-1,-1,-1):
        t = thresholds[i]
        print("Threshold: {}".format(t))

        start = timeit.default_timer()
        om.merge_to_thr(dend_pairs, dend_values, t)
        end = timeit.default_timer()
        print("Mapping completed in {} seconds".format(end-start))

        for (name, fn) in metrics:
            (f,m,s) = fn(om, name, other)
            results["{}/Full".format(name)][i] = f
            results["{}/Merge".format(name)][i] = m
            results["{}/Split".format(name)][i] = s

    if len(results) > 0:
        results["Thresholds"] = thresholds
        io_utils.write_h5_map_file( results, output_filename )
Пример #2
0
def main(seg1_fname, seg2_fname,

	calc_rand_score=True,
	calc_rand_error=True,
	calc_variation_score=True,
	calc_variation_information=True,

	relabel2d=False,
	foreground_restricted=True,
	split_0_segment=True,

	other=None):
	'''
	Script functionality, computes the overlap matrix,
    computes any specified metrics,
	and prints the results nicely
	'''

	print("Loading Data...")
	seg1 = io_utils.import_file(seg1_fname)
	seg2 = io_utils.import_file(seg2_fname)


	prep = utils.parse_fns( utils.prep_fns,
                             [relabel2d, foreground_restricted ] )
	seg1, seg2 = utils.run_preprocessing( seg1, seg2, prep )


	om = utils.calc_overlap_matrix(seg1, seg2, split_0_segment)


	#Calculating each desired metric
	metrics = utils.parse_fns( utils.metric_fns,
                               [calc_rand_score,
                                calc_rand_error,
                                calc_variation_score,
                                calc_variation_information] )

	results = {}
	for (name,metric_fn) in metrics:
	  if relabel2d:
	    full_name = "2D {}".format(name)
	  else:
	    full_name = name

	  (f,m,s) = metric_fn( om, full_name, other )
	  results["{} Full".format(name)] = f
	  results["{} Merge".format(name)] = m
	  results["{} Split".format(name)] = s


	print("")
	utils.print_metrics(results)
Пример #3
0
def main(ws_filename,
         label_filename,
         output_filename,
         thr_low,
         thr_high,
         thr_inc,
         calc_rfs=True,
         calc_re=True,
         calc_vifs=True,
         calc_vi=True,
         rel2d=False,
         foreground_restriction=False,
         split0=True,
         other=None):

    print("Reading data...")
    ws_seg, dend_pairs, dend_values = io_utils.import_ws_file(ws_filename)
    label_seg = io_utils.import_file(label_filename)
    assert ws_seg.shape == label_seg.shape

    thresholds = np.arange(thr_low, thr_high, thr_inc)

    prep = utils.parse_fns(utils.prep_fns, [rel2d, foreground_restriction])
    ws_seg, label_seg = utils.run_preprocessing(ws_seg, label_seg, prep)

    om = utils.calc_overlap_matrix(ws_seg, label_seg, split0)

    metrics = utils.parse_fns(utils.metric_fns,
                              [calc_rfs, calc_re, calc_vifs, calc_vi])

    results = init_results(metrics, len(thresholds))
    #descending threshold to allow incremental merging
    for i in range(thresholds.size - 1, -1, -1):
        t = thresholds[i]
        print("Threshold: {}".format(t))

        start = timeit.default_timer()
        om.merge_to_thr(dend_pairs, dend_values, t)
        end = timeit.default_timer()
        print("Mapping completed in {} seconds".format(end - start))

        for (name, fn) in metrics:
            (f, m, s) = fn(om, name, other)
            results["{}/Full".format(name)][i] = f
            results["{}/Merge".format(name)][i] = m
            results["{}/Split".format(name)][i] = s

    if len(results) > 0:
        results["Thresholds"] = thresholds
        io_utils.write_h5_map_file(results, output_filename)
Пример #4
0
def main(
    seg1_fname,
    seg2_fname,
    calc_rand_score=True,
    calc_rand_error=True,
    calc_variation_score=True,
    calc_variation_information=True,
    relabel2d=False,
    foreground_restricted=True,
    split_0_segment=True,
    other=None,
):
    """
	Script functionality, computes the overlap matrix,
    computes any specified metrics,
	and prints the results nicely
	"""

    print("Loading Data...")
    seg1 = io_utils.import_file(seg1_fname)
    seg2 = io_utils.import_file(seg2_fname)

    prep = utils.parse_fns(utils.prep_fns, [relabel2d, foreground_restricted])
    seg1, seg2 = utils.run_preprocessing(seg1, seg2, prep)

    om = utils.calc_overlap_matrix(seg1, seg2, split_0_segment)

    # Calculating each desired metric
    metrics = utils.parse_fns(
        utils.metric_fns, [calc_rand_score, calc_rand_error, calc_variation_score, calc_variation_information]
    )

    results = {}
    for (name, metric_fn) in metrics:
        if relabel2d:
            full_name = "2D {}".format(name)
        else:
            full_name = name

        (f, m, s) = metric_fn(om, full_name, other)
        results["{} Full".format(name)] = f
        results["{} Merge".format(name)] = m
        results["{} Split".format(name)] = s

    print("")
    utils.print_metrics(results)