Example #1
0
def process_waterz(z0a, z1a, y0a, y1a, x0a, x1a):
    out_path = get_waterz(x0a, y0a, z0a, wz_thres[-1])
    if not os.path.exists(out_path):
        # naive
        zstep = min(z1a - z0a, vol_sz[0])
        if zstep == vol_sz[0]:  # fit at least a chunk
            zz = range(z0a, z1a, vol_sz[0])
        else:
            zz = z0 + vol_sz[0] * ((z0a - z0) // vol_sz[0])
        numZ = z1a - z0a
        xx = range(x0a, x1a, vol_sz[1])
        yy = range(y0a, y1a, vol_sz[2])
        print xx, yy, zz
        aff = np.zeros((3, numZ, vol_sz[1] * len(yy), vol_sz[2] * len(xx)),
                       dtype=np.float32)

        print 'load aff'
        for xi, x in enumerate(xx):
            for yi, y in enumerate(yy):
                for kid, k in enumerate('zyx'):
                    if zstep == vol_sz[0]:  # fit at least a chunk
                        for zi, z in enumerate(zz):
                            aff[kid, zi*vol_sz[1]:(zi+1)*vol_sz[0], yi*vol_sz[1]:(yi+1)*vol_sz[1], xi*vol_sz[2]:(xi+1)*vol_sz[2]] = \
                                    np.array(h5py.File(get_aff(x, y, z)+"/%s_min.h5" % (k))['main']).astype(np.float32)/255.0
                    else:  # fit part of a chunk
                        aff[kid, :, yi*vol_sz[1]:(yi+1)*vol_sz[1], xi*vol_sz[2]:(xi+1)*vol_sz[2]] = \
                                np.array(h5py.File(get_aff(x, y, zz)+"/%s_min.h5" % (k))['main'])[z0a-zz:z1a-zz].astype(np.float32)/255.0

        print 'load 2d seg'
        if zstep == vol_sz[0]:  # fit at least a chunk
            z2d = np.zeros((numZ, vol_sz[1] * len(yy), vol_sz[2] * len(xx)),
                           dtype=np.uint64)
            for zid in range(len(zz)):
                sn = get_zwatershed(x0a, y0a, z0a + zid * vol_sz[0])
                z2d[zid * vol_sz[0]:(zid + 1) * vol_sz[0]] = np.array(
                    h5py.File(sn)['main']).astype(np.uint64)
        else:
            sn = get_zwatershed(x0a, y0a, zz)
            z2d = np.array(h5py.File(sn)['main'])[z0a - zz:z1a - zz].astype(
                np.uint64)

        # unique and relabel ids
        next_id = np.uint64(0)
        # change value by reference
        for zid in range(numZ):
            tile = z2d[zid]
            tile[np.where(tile > 0)] += next_id
            next_id = tile.max()

        print 'do segmentation'
        seg = waterz(affs=aff,
                     thresholds=wz_thres,
                     fragments=z2d,
                     merge_function=wz_mf)
        for tid, tt in enumerate(wz_thres):
            out_path = get_waterz(x0a, y0a, z0a, tt)
            writeh5(out_path, 'main', relabel(seg[tid]).astype(np.uint32))
Example #2
0
    et = time.time()
    out = relabel(out)
    sn = '%s_%f_%f_%d_%f_%d_%f_%d.h5' % (opt, T_aff[0], T_aff[1], T_thres[0],
                                         T_aff[2], T_dust, T_merge)
elif opt == '1':
    # 2D watershed + waterz
    import waterz
    print 'waterz-0.8'
    st = time.time()
    low = 0.05
    high = 0.995
    mf = 'aff85_his256'
    T_thres = [0.2]
    out = waterz.waterz(aff,
                        T_thres,
                        merge_function=mf,
                        gt_border=0,
                        aff_threshold=[low, high])[0]
    et = time.time()
    out = relabel(out)
    sn = '%s_%f_%f_%f_%s.h5' % (opt, low, high, T_thres[0], mf)
elif opt == '2':
    # 2D zwatershed + waterz
    import waterz
    import zwatershed
    print 'zwatershed + waterz'
    st = time.time()
    T_thres = [800]
    T_aff = [0.05, 0.95, 0.2]
    T_dust = 600
    T_merge = 0.9
Example #3
0
import waterz
import numpy as np

aff = np.random.random((3, 5, 5, 5)).astype(np.float32)
seg_gt = None

aff_thresholds = [0.005, 0.995]
seg_thresholds = [0.1, 0.3, 0.6]

seg = waterz.waterz(aff,
                    seg_thresholds,
                    merge_function='aff50_his256',
                    aff_threshold=aff_thresholds,
                    gt=seg_gt)
Example #4
0
    T_merge=0.9
    T_aff_rel=1
    out = zwatershed.zwatershed(aff, T_thres, T_aff=T_aff, \
                                T_dust=T_dust, T_merge=T_merge,T_aff_relative=T_aff_rel)[0][0]
    et = time.time()
    out = relabel(out)
    sn = '%s_%f_%f_%d_%f_%d_%f_%d'%(args.mode,T_aff[0],T_aff[1],T_thres[0],T_aff[2],T_dust,T_merge,T_aff_rel)

elif args.mode == 1:
    # waterz
    import waterz
    print('waterz:', waterz.__version__)
    st = time.time()
    low=0.05; high=0.995
    mf = 'aff85_his256'; T_thres = [0.3]
    out = waterz.waterz(aff, T_thres, merge_function=mf, gt_border=0,
                        fragments=None, aff_threshold=[low, high], return_seg=True, gt=seg)[0]
    et = time.time()
    out = relabel(out)
    print(out.shape)
    sn = '%s_%f_%f_%f_%s'%(args.mode,low,high,T_thres[0],mf)

elif args.mode == 2:
    # 2D zwatershed + waterz
    import waterz
    import zwatershed
    print('waterz:', waterz.__version__)
    #print('zwatershed:', zwatershed.__version__)
    st = time.time()
    T_thres = [150]
    T_aff=[0.05,0.8,0.2]
    T_dust=150