コード例 #1
0
def match_non_removable(index, verbose=True):
    if verbose and index % 2**14 == 0:
        print('PK12 LUT non-removables: %d / %d' % (index, 2**26))
    cube = t3d.cube_from_index(index=index, center=False)
    n = cube.sum()
    if n < 2:
        return True
    if n > 3:
        return False
    x, y, z = np.where(cube)
    if n == 2:
        if np.any(np.abs([x[1] - x[0], y[1] - y[0], z[1] - z[0]]) == 2):
            return True
        else:
            return False
    else:
        if np.any(np.abs(
            [x[1] - x[0], y[1] - y[0], z[1] - z[0]]) == 2) and np.any(
                np.abs([x[2] - x[0], y[2] - y[0], z[2] -
                        z[0]]) == 2) and np.any(
                            np.abs([x[1] - x[2], y[1] - y[2], z[1] -
                                    z[2]]) == 2):
            return True
        else:
            return False
コード例 #2
0
ファイル: Smoothing.py プロジェクト: suhaasa/ClearMap2
def index_to_smoothing(index, verbose = True):
  """Match index of configuration to smoothing action"""
  if verbose and index % 2**14 == 0:
    print('Smoothing LUT: %d / %d' % (index, 2**27));
  cube = t3d.cube_from_index(index=index, center=None);
  return cube_to_smoothing(cube);
コード例 #3
0
def match_index(index, verbose=True):
    if verbose and index % 2**14 == 0:
        print('PK12 LUT: %d / %d' % (index, 2**26))
    cube = t3d.cube_from_index(index=index, center=True)
    return match(cube)
コード例 #4
0
ファイル: Topology3d.py プロジェクト: suhaasa/ClearMap2
def _test():
    import numpy as np
    import ClearMap.ImageProcessing.Topology.Topology3d as top

    from importlib import reload
    reload(top)

    label = top.cube_labeled()
    top.print_cube(label)

    # Test rotations
    c = np.zeros((3, 3, 3), dtype=bool)
    c[1, 0, 0] = True
    top.print_cube(c)

    cs = [top.rotate(c, axis=2, steps=r) for r in range(4)]
    [top.print_cube(cc) for cc in cs]

    reload(top)
    l = top.cube_labeled()
    rts = top.rotations6(l)

    [top.print_cube(r) for r in rts]

    reload(top)
    b = top.cube_from_index(6)
    i = top.cube_to_index(b)
    print(i, 6)

    us = np.zeros((3, 3, 3), dtype=int)
    us[1, 1, 2] = 1
    us[1, 0, 1] = 1
    us[1, 2, 0] = 2

    r12 = top.rotations12(us)
    [top.print_cube(cc) for cc in r12]

    #check configuration utlity
    reload(top)
    index = 11607
    source = top.cube_from_index(index)

    c = top.index_from_binary(source)
    c[1, 1, 1] == index

    x = np.random.rand(1500, 500, 500) > 0.6
    c = top.index_from_binary(x)

    import numpy as np
    import ClearMap.ImageProcessing.Topology.Topology3d as top

    #check fortran vs c order
    x = np.random.rand(5, 5, 5) > 0.35
    y = np.asanyarray(x, order='F')

    ix = top.index_from_binary(x)
    iy = top.index_from_binary(y)

    ax = ix.array
    ay = iy.array

    #%% profile
    import io
    io.DEFAULT_BUFFER_SIZE = 2**32

    import pstats, cProfile

    import numpy as np
    import ClearMap.ImageProcessing.Topology.Topology3d as top

    x = np.ones((3000, 500, 1000), dtype=bool, order='F')

    import ClearMap.IO.IO as io
    import ClearMap.ParallelProcessing.DataProcessing.ArrayProcessing as ap
    ap.write('test.npy', x)

    y = io.as_source('test.npy')
    z = io.create('resuly.npy', shape=y.shape, order='C', dtype='uint32')

    cProfile.runctx(
        "c =top.index_from_binary(y, method='!shared', sink=z, verbose=True, processes=None)",
        globals(), locals(), "Profile.prof")

    s = pstats.Stats("Profile.prof")
    s.strip_dirs().sort_stats("time").print_stats()

    import mmap
    mmap.ACCESS_COPY