def main(args): substack = SubStack(args.indir,args.substack_id) patch = substack.get_volume() histogram = np.histogram(patch, bins=256,range=(0,256))[0] thresholds = threshold.multi_kapur(histogram, 2) outfile=args.outdir+'/'+args.substack_id+'/'+basename(args.indir) mkdir_p(args.outdir+'/'+args.substack_id) f=open(outfile,'w') f.write(str(thresholds[0])+','+str(thresholds[1])+'\n') f.close()
def main(args): substack = SubStack(args.indir, args.substack_id) patch = substack.get_volume() histogram = np.histogram(patch, bins=256, range=(0, 256))[0] thresholds = threshold.multi_kapur(histogram, 2) outfile = args.outdir + '/' + args.substack_id + '/' + basename(args.indir) mkdir_p(args.outdir + '/' + args.substack_id) f = open(outfile, 'w') f.write(str(thresholds[0]) + ',' + str(thresholds[1]) + '\n') f.close()
def main(args): total_start = timeit.default_timer() print('Starting reconstruction of volume %s ...'%(args.substack_id)) substack = SubStack(args.indir,args.substack_id) substack.load_volume() tensor = substack.get_volume() # Changing the tensor so that it has a 6 pixel black padding. Hopefully it won't frick things up too much. Else, mail time. print("The shape of the tensor before padding: " + str(np.shape(tensor))) tensor = pad(tensor, 6) print("The shape of the tensor after padding: " + str(np.shape(tensor))) if not args.local_mean_std: print('Reading standardization data from', args.trainfile) h5 = tables.openFile(args.trainfile) Xmean = h5.root.Xmean[:].astype(np.float32) Xstd = h5.root.Xstd[:].astype(np.float32) h5.close() else: Xmean=None Xstd=None print('Starting semantic devonvolution of volume', args.substack_id) # Importing here to have a clean --help from keras.models import model_from_json model = model_from_json(open(args.model + '/architecture.json').read()) model.load_weights(args.model + '/weights.h5') minz = int(re.split('[a-zA-z0-9]*_',substack.info['Files'][0])[1].split('.tif')[0]) # Remove the margin, I have changed deconvolver to use a fized number instead of the extramargin. Hope it works. reconstruction = deconvolver.filter_volume(tensor, Xmean, Xstd, args.extramargin, model, args.speedup, do_cython=args.do_cython, trainfile=args.trainfile) imtensor.save_tensor_as_tif(reconstruction, args.outdir+'/'+args.substack_id, minz) print ("total time reconstruction: %s" %(str(timeit.default_timer() - total_start)))
def get_visible_pairs(base_indir,substack_id,view_ids,lower_threshold=30.): num_vis=0 for view_id in view_ids: substack = SubStack(base_indir+'/'+view_id,args.substack_id) patch = substack.get_volume() histogram = np.histogram(patch, bins=256,range=(0,256))[0] thresholds = threshold.multi_kapur(histogram, 2) if thresholds[1]>=lower_threshold: num_vis+=1 threshold_0=thresholds[0] threshold_1=thresholds[1] threshold_2=thresholds[2] threshold_3=thresholds[3] list_views=[] if num_vis==0: return list_views elif num_vis==1: if threshold_0>=lower_threshold: list_views.append(tuple((view_ids[0],view_ids[1]))) list_views.append(tuple((view_ids[0],view_ids[3]))) if threshold_1>=lower_threshold: list_views.append(tuple((view_ids[0],view_ids[1]))) list_views.append(tuple((view_ids[2],view_ids[1]))) if threshold_2>=lower_threshold: list_views.append(tuple((view_ids[2],view_ids[1]))) list_views.append(tuple((view_ids[2],view_ids[3]))) if threshold_3>=lower_threshold: list_views.append(tuple((view_ids[0],view_ids[3]))) list_views.append(tuple((view_ids[2],view_ids[3]))) elif num_vis==2: if (threshold_0>=lower_threshold and threshold_2>=lower_threshold) or (threshold_1>=lower_threshold and threshold_3>=lower_threshold): list_views.append(tuple((view_ids[0],view_ids[1]))) list_views.append(tuple((view_ids[0],view_ids[3]))) list_views.append(tuple((view_ids[2],view_ids[1]))) list_views.append(tuple((view_ids[2],view_ids[3]))) elif threshold_0>=lower_threshold and threshold_1>=lower_threshold: list_views.append(tuple((view_ids[0],view_ids[1]))) elif threshold_0>=lower_threshold and threshold_3>=lower_threshold: list_views.append(tuple((view_ids[0],view_ids[3]))) elif threshold_2>=lower_threshold and threshold_1>=lower_threshold: list_views.append(tuple((view_ids[2],view_ids[1]))) elif threshold_2>=lower_threshold and threshold_3>=lower_threshold: list_views.append(tuple((view_ids[2],view_ids[3]))) elif num_vis==3: if threshold_0 < lower_threshold: list_views.append(tuple((view_ids[2],view_ids[1]))) list_views.append(tuple((view_ids[2],view_ids[3]))) elif threshold_2 < lower_threshold: list_views.append(tuple((view_ids[0],view_ids[1]))) list_views.append(tuple((view_ids[0],view_ids[3]))) elif threshold_1 < lower_threshold or threshold_3 < lower_threshold: list_views.append(tuple((view_ids[0],view_ids[1]))) list_views.append(tuple((view_ids[0],view_ids[3]))) list_views.append(tuple((view_ids[2],view_ids[1]))) list_views.append(tuple((view_ids[2],view_ids[3]))) elif num_vis==4: list_views.append(tuple((view_ids[0],view_ids[1]))) list_views.append(tuple((view_ids[0],view_ids[3]))) list_views.append(tuple((view_ids[2],view_ids[1]))) list_views.append(tuple((view_ids[2],view_ids[3]))) return list_views
def get_visible_pairs(base_indir, substack_id, view_ids, lower_threshold=30.): num_vis = 0 for view_id in view_ids: substack = SubStack(base_indir + '/' + view_id, args.substack_id) patch = substack.get_volume() histogram = np.histogram(patch, bins=256, range=(0, 256))[0] thresholds = threshold.multi_kapur(histogram, 2) if thresholds[1] >= lower_threshold: num_vis += 1 threshold_0 = thresholds[0] threshold_1 = thresholds[1] threshold_2 = thresholds[2] threshold_3 = thresholds[3] list_views = [] if num_vis == 0: return list_views elif num_vis == 1: if threshold_0 >= lower_threshold: list_views.append(tuple((view_ids[0], view_ids[1]))) list_views.append(tuple((view_ids[0], view_ids[3]))) if threshold_1 >= lower_threshold: list_views.append(tuple((view_ids[0], view_ids[1]))) list_views.append(tuple((view_ids[2], view_ids[1]))) if threshold_2 >= lower_threshold: list_views.append(tuple((view_ids[2], view_ids[1]))) list_views.append(tuple((view_ids[2], view_ids[3]))) if threshold_3 >= lower_threshold: list_views.append(tuple((view_ids[0], view_ids[3]))) list_views.append(tuple((view_ids[2], view_ids[3]))) elif num_vis == 2: if (threshold_0 >= lower_threshold and threshold_2 >= lower_threshold ) or (threshold_1 >= lower_threshold and threshold_3 >= lower_threshold): list_views.append(tuple((view_ids[0], view_ids[1]))) list_views.append(tuple((view_ids[0], view_ids[3]))) list_views.append(tuple((view_ids[2], view_ids[1]))) list_views.append(tuple((view_ids[2], view_ids[3]))) elif threshold_0 >= lower_threshold and threshold_1 >= lower_threshold: list_views.append(tuple((view_ids[0], view_ids[1]))) elif threshold_0 >= lower_threshold and threshold_3 >= lower_threshold: list_views.append(tuple((view_ids[0], view_ids[3]))) elif threshold_2 >= lower_threshold and threshold_1 >= lower_threshold: list_views.append(tuple((view_ids[2], view_ids[1]))) elif threshold_2 >= lower_threshold and threshold_3 >= lower_threshold: list_views.append(tuple((view_ids[2], view_ids[3]))) elif num_vis == 3: if threshold_0 < lower_threshold: list_views.append(tuple((view_ids[2], view_ids[1]))) list_views.append(tuple((view_ids[2], view_ids[3]))) elif threshold_2 < lower_threshold: list_views.append(tuple((view_ids[0], view_ids[1]))) list_views.append(tuple((view_ids[0], view_ids[3]))) elif threshold_1 < lower_threshold or threshold_3 < lower_threshold: list_views.append(tuple((view_ids[0], view_ids[1]))) list_views.append(tuple((view_ids[0], view_ids[3]))) list_views.append(tuple((view_ids[2], view_ids[1]))) list_views.append(tuple((view_ids[2], view_ids[3]))) elif num_vis == 4: list_views.append(tuple((view_ids[0], view_ids[1]))) list_views.append(tuple((view_ids[0], view_ids[3]))) list_views.append(tuple((view_ids[2], view_ids[1]))) list_views.append(tuple((view_ids[2], view_ids[3]))) return list_views