示例#1
0
def main(args):
    ws_id = generate_ws_id(args.min_seed_size, args.connectivity, 
        args.smooth_thresh, args.keep_speckles, args.override_skimage)
    paths = get_paths("XX", args.traintest, args.size, args.volume_id, 
        "idsia", "XX", "XX", "XX", ws_id)
    stack = read_h5(paths["hypercubes"], args.h5_key)
    if args.dry_run: stack = stack[:2,:,:]
    if not args.dont_invert: stack[...] = invert_gray(stack)
    ws = np.zeros(stack.shape)
    cur_max = 0
    for ii in range(stack.shape[0]):
        print ii
        ws[ii,:,:] = morpho.watershed(stack[ii,:,:], minimum_seed_size=args.min_seed_size,
            connectivity=args.connectivity, smooth_thresh=args.smooth_thresh,
            override_skimage=args.override_skimage) + cur_max
        cur_max = ws[ii,:,:].max()
    ws = ws.astype('int64')
    print "unique labels in ws:",np.unique(ws).size
    if not args.keep_speckles:
        ws = agglo.despeckle_watershed(ws)
        print "unique labels after despeckling:",np.unique(ws).size
    ws, _, _ = evaluate.relabel_from_one(ws)
    if ws.min() < 1: ws += (1-ws.min())
    write_h5(ws, paths["watersheds"], dry=args.dry_run)
    if args.no_quarters or (args.size != "whole"): return
    for row_start, row_end, col_start, col_end, frame_start, frame_end, label, size in fractions:
        path = generate_path(args.traintest, size, label, ws_id)
        write_h5(ws[frame_start:frame_end, row_start:row_end, col_start:col_end], path)
示例#2
0
    print ii
    ws_train[ii, :, :] = morpho.watershed(
        1 - membraneTrain[ii, :, :],
        connectivity=connectivity,
        smooth_thresh=smooth_thresh,
        override_skimage=override,
        minimum_seed_size=min_seed_size) + cur_max

    cur_max = ws_train[ii, :, :].max()

ws_train = ws_train.astype('int64')
print "unique labels in ws:", np.unique(ws_train).size

ws_train = optimized.despeckle_watershed(ws_train)
print "unique labels after despeckling:", np.unique(ws_train).size
ws_train, _, _ = evaluate.relabel_from_one(ws_train)

if ws_train.min() < 1:
    ws_train += (1 - ws_train.min())

ws_train = ws_train.astype('int64')
print "Training watershed complete"

print "Watershed train (VI, ARI)"
vi_ws_train = ev.split_vi(ws_train, gt_train),
ari_ws_train = ev.adj_rand_index(ws_train, gt_train)
print vi_ws_train
print ari_ws_train

scipy.io.savemat('trainWS.mat', mdict={'ws_train': ws_train})
scipy.io.savemat('trainMembrane.mat', mdict={'membraneTrain': membraneTrain})
示例#3
0
# create graph and obtain a training dataset

if algo == 1: #run gala
    fc = features.base.Composite(children=[features.moments.Manager(), features.histogram.Manager(25, 0, 1, [0.1, 0.5, 0.9]), 
        features.graph.Manager(), features.contact.Manager([0.1, 0.5, 0.9]) ])

    rf = classify.load_classifier(sys.argv[6])
    learned_policy = agglo.classifier_probability(fc, rf)
    
    print 'applying classifier...'
    g_test = agglo.Rag(ws, membrane, learned_policy, feature_manager=fc)
    print 'choosing best operating point...'
    g_test.agglomerate(thresh) # best expected segmentation
    cube = g_test.get_segmentation()
    cube, _, _ = evaluate.relabel_from_one(cube)
    print "Completed Gala Run"


# gala allows implementation of other agglomerative algorithms, including
# the default, mean agglomeration

if algo == 2: #mean agglomeration
    print 'mean agglomeration step...'

    g_testm = agglo.Rag(ws, membrane, merge_priority_function=agglo.boundary_mean)
    g_testm.agglomerate(thresh)
    cube = g_testm.get_segmentation()
    cube, _, _ = evaluate.relabel_from_one(cube)

    print "Completed Mean Agglo"
示例#4
0
文件: galaRun.py 项目: wrgr/macho
    fc = features.base.Composite(children=[
        features.moments.Manager(),
        features.histogram.Manager(25, 0, 1, [0.1, 0.5, 0.9]),
        features.graph.Manager(),
        features.contact.Manager([0.1, 0.5, 0.9])
    ])

    rf = classify.load_classifier(sys.argv[6])
    learned_policy = agglo.classifier_probability(fc, rf)

    print 'applying classifier...'
    g_test = agglo.Rag(ws, membrane, learned_policy, feature_manager=fc)
    print 'choosing best operating point...'
    g_test.agglomerate(thresh)  # best expected segmentation
    cube = g_test.get_segmentation()
    cube, _, _ = evaluate.relabel_from_one(cube)
    print "Completed Gala Run"

# gala allows implementation of other agglomerative algorithms, including
# the default, mean agglomeration

if algo == 2:  #mean agglomeration
    print 'mean agglomeration step...'

    g_testm = agglo.Rag(ws,
                        membrane,
                        merge_priority_function=agglo.boundary_mean)
    g_testm.agglomerate(thresh)
    cube = g_testm.get_segmentation()
    cube, _, _ = evaluate.relabel_from_one(cube)
ws_test=np.zeros(membraneTest.shape)
cur_max = 0
for ii in range(membraneTest.shape[0]):
    print ii
    ws_test[ii,:,:] = morpho.watershed(membraneTest[ii,:,:],
    connectivity=connectivity, smooth_thresh=smooth_thresh,
    override_skimage=override,minimum_seed_size=min_seed_size) + cur_max
    cur_max = ws_test[ii,:,:].max()

print ws_test.dtype
ws_test = ws_test.astype('int64')
print "unique labels in ws:",np.unique(ws_test).size
    
ws_test = optimized.despeckle_watershed(ws_test)
print "unique labels after despeckling:",np.unique(ws_test).size
ws_test, _, _ = evaluate.relabel_from_one(ws_test)
    
if ws_test.min() < 1: 
    ws_test += (1-ws_test.min())

print "Testing watershed complete"

print "Watershed test (VI, ARI)"
vi_ws_test = ev.split_vi(ws_test, gt_test),
ari_ws_test = ev.adj_rand_index(ws_test, gt_test)
print vi_ws_test
print ari_ws_test

scipy.io.savemat('testWS.mat', mdict={'ws_test':ws_test})

print 'Time Elapsed So Far: ' + str(time.time()-start)