In [1]:
%load_ext autoreload
%autoreload 2
from matplotlib.pyplot import imshow
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
import cPickle as pickle
import os; import sys; sys.path.append('..')
import gp
import gp.nets as nets
In [3]:
import numpy as np
import mahotas as mh
In [17]:
image, prob, gold, rhoana, bb = gp.Legacy.read_dojo_data()
In [35]:
gp.Util.view(rhoana[9],large=True)
In [19]:
gp.Util.view(rhoana[1])
In [8]:
gp.Util.view(gold[2])
In [1]:
rhoana
In [7]:
gp.Util.view(gold[0])
In [16]:
import h5py
import mahotas as mh
import numpy as np
In [13]:
#
# create gold h5 for neuroproof
#
all_labels = mh.fullhistogram(gold.astype(np.uint64))
all_labels = np.where(all_labels!=0)
transforms = np.zeros((all_labels[0].shape[0],2), dtype=np.uint64)
transforms[:,0] = all_labels[0]
transforms[:,1] = all_labels[0]
with h5py.File('/home/d/fp_data/gold.h5', 'w') as hf:
hf.create_dataset('stack', data=gold)
hf.create_dataset('transforms', data=transforms)
In [16]:
#
# create rhoana h5 for neuroproof
#
# for z in range(10):
# rhoana[z] += 100*z
# for z in range(10):
# print rhoana[z].min(), rhoana[z].max()
import h5py
all_labels = mh.fullhistogram(rhoana[z].astype(np.uint64))
all_labels = np.where(all_labels!=0)
transforms = np.zeros((all_labels[0].shape[0],2), dtype=np.uint64)
transforms[:,0] = all_labels[0]
transforms[:,1] = all_labels[0]
with h5py.File('/home/d/FP/dojoNEW/rhoana_'+str(z)+'.h5', 'w') as hf:
hf.create_dataset('stack', data=rhoana)
hf.create_dataset('transforms', data=transforms)
In [4]:
golds = np.zeros((30,500,500), dtype=np.uint64)
probs = np.zeros((30,500,500), dtype=np.uint8)
rhoanas = np.zeros((30,500,500), dtype=np.uint64)
# for z in range(0,50):
test_slices = range(15,25) + range(40,50) + range(65,75)
for i,z in enumerate(test_slices):
image, prob, gold, rhoana = gp.Util.read_cremi_section(os.path.expanduser('/home/d/data/CREMIGP/TEST/'), z)
# input_image.append(image[0:500,0:500])
# input_prob.append(255.-prob[0:500,0:500])
# input_gold.append(gold[0:500,0:500])
# input_rhoana.append(rhoana[0:500,0:500])
golds[i] = gold[0:500,0:500]
probs[i] = 255.-prob[0:500,0:500]
rhoanas[i] = rhoana[0:500,0:500]
In [6]:
#
# now in 2d !!!!! FOR CREMI
#
import h5py
for z in range(30):
print rhoanas[z:z+1].max()
slice
all_labels = mh.fullhistogram(rhoanas[z:z+1].astype(np.uint64))
all_labels = np.where(all_labels!=0)
transforms = np.zeros((all_labels[0].shape[0],2), dtype=np.uint64)
transforms[:,0] = all_labels[0]
transforms[:,1] = all_labels[0]
with h5py.File('/home/d/FP/CREMITEST/rhoana_'+str(z)+'.h5', 'w') as hf:
hf.create_dataset('stack', data=rhoanas[z:z+1])
hf.create_dataset('transforms', data=transforms)
In [7]:
for z in range(30):
p1 = probs[z:z+1].copy()
# has to be x,y,z and is z,y,x
p1 = p1.swapaxes(0,2)
p1 = p1.swapaxes(0,1)
p2 = p1.copy()
p2 = 255-p2
p_2channels = np.zeros((p1.shape[0],p1.shape[1],p1.shape[2],2), dtype=np.float32)
print p_2channels.shape
p_2channels[:,:,:,0] = p1 / 255.
p_2channels[:,:,:,1] = p2 / 255.
with h5py.File('/home/d/FP/CREMITEST/prob_'+str(z)+'.h5', 'w') as hf:
hf.create_dataset('volume/predictions', data=p_2channels)
In [36]:
#
#
# now for cylinder!!! in 2D!!!
#
In [71]:
for z in range(250,300):
image, prob, mask, gold, rhoana = gp.Util.read_section('/home/d/data/cylinderNEW',z)
prob = 255-prob
prob[mask==0] = 0
prob = prob.reshape((1, prob.shape[0], prob.shape[1]))
p1 = prob.copy()
# has to be x,y,z and is z,y,x
p1 = p1.swapaxes(0,2)
p1 = p1.swapaxes(0,1)
p2 = p1.copy()
p2 = 255-p2
p_2channels = np.zeros((p1.shape[0],p1.shape[1],p1.shape[2],2), dtype=np.float32)
print p_2channels.shape
p_2channels[:,:,:,0] = p1 / 255.
p_2channels[:,:,:,1] = p2 / 255.
with h5py.File('/home/d/FP/cylinder/prob_'+str(z)+'.h5', 'w') as hf:
hf.create_dataset('volume/predictions', data=p_2channels)
# print rhoana[z:z+1].max()
# slice
all_labels = mh.fullhistogram(rhoana.astype(np.uint64))
all_labels = np.where(all_labels!=0)
transforms = np.zeros((all_labels[0].shape[0],2), dtype=np.uint64)
transforms[:,0] = all_labels[0]
transforms[:,1] = all_labels[0]
rhoana = rhoana.reshape((1, rhoana.shape[0], rhoana.shape[1]))
with h5py.File('/home/d/FP/cylinder/rhoana_'+str(z)+'.h5', 'w') as hf:
hf.create_dataset('stack', data=rhoana)
hf.create_dataset('transforms', data=transforms)
print z
In [61]:
imshow(p2[:,:,0],cmap='gray')
Out[61]:
In [72]:
rhoana[0].max()
Out[72]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [28]:
p1 = prob[z:z+1].copy()
In [29]:
p1.shape
Out[29]:
In [30]:
p1 = p1.swapaxes(0,2)
In [31]:
p1.shape
Out[31]:
In [ ]:
In [ ]:
In [1]:
cmd = 'neuroproof_graph_predict rhoana_{z}.h5 prob_{z}.h5 classifier.h5 --output-file segmentation_{z}.h5 --graph-file graph_{z}.json --threshold 0'
for z in range(0,75):
c = cmd.replace('{z}',str(z))
print c
In [ ]:
In [ ]:
In [15]:
#
# create prob h5 for neuroproof
#
p1 = prob.copy()
# has to be x,y,z
p1 = p1.swapaxes(0,2)
p1 = p1.swapaxes(0,1)
p2 = p1.copy()
p2 = 255-p2
p_2channels = np.zeros((prob.shape[2],prob.shape[1],prob.shape[0],2), dtype=np.float32)
p_2channels[:,:,:,0] = p1 / 255.
p_2channels[:,:,:,1] = p2 / 255.
with h5py.File('/home/d/fp_data/prob.h5', 'w') as hf:
hf.create_dataset('volume/predictions', data=p_2channels)
In [6]:
image.shape
Out[6]:
In [7]:
for z in range(10):
mh.imsave('/home/d/dojo_xp/data/dojo_data_vis2014/images/'+str(z)+'.png', image[z])
In [28]:
image, prob, gold, rhoana, bb = gp.Legacy.read_dojo_test_data()
In [36]:
imshow(image[1], cmap='gray')
Out[36]:
In [34]:
imshow(rhoana[2])
Out[34]:
In [31]:
import h5py
In [32]:
#
# create gold h5 for neuroproof
#
all_labels = mh.fullhistogram(gold.astype(np.uint64))
all_labels = np.where(all_labels!=0)
transforms = np.zeros((all_labels[0].shape[0],2), dtype=np.uint64)
transforms[:,0] = all_labels[0]
transforms[:,1] = all_labels[0]
with h5py.File('/home/d/FP/dojo_test/gold.h5', 'w') as hf:
hf.create_dataset('stack', data=gold)
hf.create_dataset('transforms', data=transforms)
In [33]:
#
# create rhoana h5 for neuroproof
#
all_labels = mh.fullhistogram(rhoana.astype(np.uint64))
all_labels = np.where(all_labels!=0)
transforms = np.zeros((all_labels[0].shape[0],2), dtype=np.uint64)
transforms[:,0] = all_labels[0]
transforms[:,1] = all_labels[0]
with h5py.File('/home/d/FP/dojo_test/rhoana.h5', 'w') as hf:
hf.create_dataset('stack', data=rhoana)
hf.create_dataset('transforms', data=transforms)
In [44]:
fpseg = None
with h5py.File('/home/d/FP/dojo/segmentation.h5', 'r') as hf:
list_of_names = []
hf.visit(list_of_names.append)
fpseg = hf['stack'].value
In [45]:
fpseg.shape
Out[45]:
In [48]:
gp.Util.view(fpseg[0])
In [49]:
gp.Util.view(gold[0])
In [50]:
gp.Util.view(rhoana[0])
In [51]:
gp.Util.vi(rhoana[0], fpseg[0])
Out[51]:
In [52]:
gp.Util.vi(rhoana[0], gold[0])
Out[52]:
In [53]:
gp.Util.vi(gold[0], fpseg[0])
Out[53]:
In [ ]: