def demo_data_image(): ids = h5load( '/home/mfk/axon/mkilling/devel/data/BirdGT/j0126_bird_new/j0126 cubeSegmentor category-volume_gt__016-kkiesl-20150913-205217-final.h5') ids, raw = ids[1], ids[0] ids = np.transpose(ids, (2, 0, 1)) raw = np.transpose(raw, (2, 0, 1)) ids2 = np.unique(ids, return_inverse=True)[1].reshape(ids.shape) barrier = image.ids2barriers(ids, dilute=[0, 0, 0], ecs_as_barr=True) barrier, raw = image.center_cubes(barrier, raw, crop=True) barrier2 = image.smearbarriers(barrier, kernel=(3, 5, 5)) # (z,x,y) # fig, scroller = _scroll_plot2([barrier2, (0.75*raw+0.25*255*(1-barrier))], ['ids', 'raw']) # fig, scroller = _scroll_plot2([barrier2.T, (0.75*raw.T+0.25*255*(1-barrier.T))], ['ids', 'raw']) # fig, scroller = _scroll_plot2([barrier2.T, barrier.T], ['ids', 'raw']) # fig, scroller = _scroll_plot2([barrier2, barrier], ['ids', 'raw']) fig, scroller = _scroll_plot4( [barrier2, barrier, (barrier2 > 0.5) - barrier, barrier2 > 0.5], ['bar1', 'bar2', 'ids', 'raw']) fig.show() seg = image.seg_old(barrier2 * 255) fig, scroller = _scroll_plot4([barrier2, seg, ids2, raw], ['bar1', 'seg', 'ids', 'raw']) fig.show() ri = timeit(image.rand_index) print(ri(ids2, seg)) # ~ 0.99 fig, scroller = scroll_plot(raw.T, ['raw']) fig.show()
def demo_quiver(): data = h5py.File( "/home/mfk/lustre/mkilling/BirdGT/skeleton/rel_direc+branch+barr+obj_zyx.h5" )['combi'] stack = data[:, 50:50 + 50, 50:300 + 50, 50:300 + 50] # z_i =5 # barr = stack[4,z_i] # x = stack[2,z_i] # y = stack[1,z_i] # z = stack[0,z_i] # my_quiver(x, y, barr, z) # stack has spatial shape (f,z,y,x) # stack[0]: how the vec field changes along z, i.e. 0 spatial dim # stack[1]: how the vec field changes along y, i.e. 1 spatial dim # stack[2]: how the vec field changes along x, i.e. 2 spatial dim direction_iso = [1, 0, 0] direction_iso /= np.linalg.norm(direction_iso) gamma = 0 * np.pi / 180 img_new, target_new, M = transformations.get_tracing_slice( stack[4:5], [10, 80, 80], [25, 150, 150], direction_iso=direction_iso, gamma=gamma, target=stack, target_ps=[10, 80, 80], target_vec_ix=[[0, 1, 2]], target_discrete_ix=[3, 4, 5, 6, 7, 8]) z_i = 2 # barr = target_new[4,z_i] # x = target_new[2,z_i] # y = target_new[1,z_i] # z = target_new[0,z_i] # my_quiver(x, y, barr, z) # # zz,yy,xx = np.mgrid[:5:1,:40:1,:40:1] # mlab.quiver3d(zz,yy,xx, target_new[0, ::2, ::2, ::2], target_new[1, ::2, ::2, ::2], target_new[2, ::2, ::2, ::2]) fig = scroll_plot(target_new[:, z_i], 'channels')
#R[3,1] = 0.002 ps = [31, 131, 131] z_shift = 0 aniso_factor = 2 sample_aniso = True dest_center = np.array(ps, dtype=np.float32) / 2 dest_center[0] -= z_shift # sign? T_src = translate(-pos[0], -pos[1], -pos[2]) S_src = scale(aniso_factor, 1, 1) if sample_aniso: S_dest = scale(1.0 / aniso_factor, 1, 1) else: S_dest = identity() T_dest = translate(dest_center[0], dest_center[1], dest_center[2]) M = chain_matrices([T_dest, S_dest, R, S_src, T_src]) for i in range(5): img_new, targ_new = warp_time(img, ps, M, target=targ, target_ps=[11, 121, 121], target_discrete_ix=[0, 1, 2]) #f0 = scroll_plot(img_new[0]) i, t = center_cubes(img_new, targ_new) f1 = scroll_plot([i[0], t[0]])
# a0 = arr[0:100, 0:400, 0:200] # a1 = arr[0:100, 100:400+100, 100:200+100] # b = arr[0:640, 0:640, 0:384] # c = arr[500:600, 500:800, 500:800] # kds = KnossosDataset() kds.initialize_from_knossos_path(path) get = utils.timeit(kds.from_raw_cubes_to_matrix) # a0 = arr.cut_slice(sh, off) # a1 = get(sh[[2,1,0]], off[[2,1,0]]) # a2 = (a1.T).astype(np.float32)/255 # print(np.allclose(a0, a2)) # fig = scroll_plot2([a0, a2], 'ab') t = 0 out = np.empty(sh, dtype=np.float32) N = 500 for i in range(N): t0 = time.time() a = arr.cut_slice(sh, off, out=out) t += time.time() - t0 time.sleep(0.2) off += np.random.randint(0, 10, size=3) print("%.3f slices/s" % (float(N) / t)) arr._clear_q(None) fig = scroll_plot(out, 'a')
# #stuff.append([img, pred, fig]) # #[59+32,385+32,385+32] = 0.27 #[59+32,385+32+32,385+32+32] = 0.28 #[59+32,385+3*32,385+3*32] = 0.29 #import numpy as np #from elektronn2.utils import gpu #gpu.initgpu('auto') #from elektronn2 import neuromancer #model_path = "~/axon/mkilling/CNN_Training/3D/DualScale/DS-2-1-2xConv/Backup/DS-2-1-2xConv-88.0h.mdl" #model = neuromancer.model.modelload(model_path, imposed_patch_size=[59+32,385+3*32,385+3*32]) #x = np.random.rand(*model.input_node.shape.shape[1:]).astype(np.float32) #y = model.predict_dense(x) #y = model.predict_dense(x) #y = model.predict_dense(x) model = neuromancer.model.modelload( "/home/mfk/CNN_Training/3D/DS-3-0/Backup/DS-3-0-400k.mdl", imposed_patch_size=[59 - 16, 385 - 32, 385 - 32]) pred, img = predict_centered(knossos_raw, model, [6092, 5551, 3135][::-1], excess=[0, 4, 4]) barr = pred[1] + pred[2] pc = colorize_10ch(pred) fig = scroll_plot(pc, '1234') img = pc[3, 407:-408, 407:-408] plt.imsave( "/home/mfk/axon/mkilling/investigation/MA-TEX/figures/sXY_6092_5551_3135_dscnn2.png", img)