Exemplo n.º 1
0
     display_result = True
     if display_result:  
         visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'], 
                                     dataset.class_names, r['scores'], ax=ax,
                                     title="Predictions")
         plt.savefig(folder +dataset.image_info[image_id]['id'][:-4]+'_mrcnn_result.pdf')
         plt.close()
     
     mask_pr = r['masks'].copy().transpose([2,0,1])*1.
     mask_gt = gt_mask.copy().transpose([2,0,1])*1.
     
     print("MASK GT INFO", mask_gt.shape,  mask_gt.dtype)
     print("MASK PR INFO", mask_pr.shape, mask_pr.dtype)
     print(mask_pr)
     tp_gt, tp_comp, fn_gt, fp_comp, performance_cons_off = nf_match_neurons_in_binary_masks(
             mask_gt, mask_pr, thresh_cost=0.7, min_dist=10, print_assignment=True,
             plot_results=True, Cn=image[:,:,0], labels=['GT', 'MRCNN'])
     plt.savefig(folder +dataset.image_info[image_id]['id'][:-4]+'_compare.pdf')
     plt.close()
     performance[info['id'][:-4]] = performance_cons_off
     #F1[dataset.image_info[image_id]['id'][:-4]] = performance_cons_off['f1_score']
     #recall[dataset.image_info[image_id]['id'][:-4]] = performance_cons_off['recall']
     #precision[dataset.image_info[image_id]['id'][:-4]] = performance_cons_off['precision']
     #number[dataset.image_info[image_id]['id'][:-4]] = dataset.image_info[image_id]['polygons'].shape[0]
     
     number[dataset.image_info[image_id]['id'][:-4]] = [mask_gt.shape[0], mask_pr.shape[0]]
 
 
 folder = ROOT_DIR + f'/result_f1/CellFie/1130T2159_2_detect_{detect}_nms_{post}_rpn_{rpn}/' 
 try:
     os.makedirs(folder)
Exemplo n.º 2
0
mask0 = mask[seq[idx_list]]
mask1 = caiman_estimates.A.toarray()[:, caiman_estimates.idx].reshape(
    (512, 128, -1), order='F').transpose([2, 0, 1])
mask1[mask1 > 0.02] = 1
plt.figure()
plt.imshow(mask0.sum(0))
plt.colorbar()
plt.show()

from caiman.base.rois import nf_match_neurons_in_binary_masks
tp_gt, tp_comp, fn_gt, fp_comp, performance_cons_off = nf_match_neurons_in_binary_masks(
    mask0,
    mask1,
    thresh_cost=1,
    min_dist=10,
    print_assignment=True,
    plot_results=True,
    Cn=mov[0],
    labels=['viola', 'cm'])

#%%
caiman_estimates.idx
plt.figure()
plt.plot(signal_filter(caiman_estimates.C, freq=15, fr=400)[idx])
plt.figure()
plt.imshow(caiman_estimates.A[:, idx].toarray().reshape((512, 128), order='F'))

#%%
#mask0 = mask[seq[idx_list]]
mask0 = vpy['weights'][idx_list].copy()
Exemplo n.º 3
0
        v = np.load(os.path.join(v_folder, v_file), allow_pickle=True).item()
        
        
        v_spatial = v['weights'].copy()
        v_temporal = v['t'].copy()
        v_ROIs = v['ROIs'].copy()
        v_ROIs = v_ROIs * 1.0
        v_templates = v['templates'].copy()
        v_spikes = v['spikes'].copy()
        
        #plt.figure(); plt.suptitle(f'distance:{dist}');plt.subplot(1,2,1);plt.imshow(v_spatial[0]); plt.subplot(1,2,2);plt.imshow(v_spatial[1]);
        #plt.figure(); plt.suptitle(f'distance:{dist}');plt.subplot(1,2,1);plt.imshow(v_spatial[0]); plt.subplot(1,2,2);plt.imshow(v_spatial[1]);
        
#%%        
        tp_gt, tp_comp, fn_gt, fp_comp, performance_cons_off = nf_match_neurons_in_binary_masks(
                spatial, v_ROIs, thresh_cost=1, min_dist=10, print_assignment=True,
                plot_results=True, Cn=summary[2], labels=['gt', 'volpy'])   
        
        plt.savefig(os.path.join(SAVE_FOLDER, 'simulation_Mask_RCNN_result_spikeamp_0.1_corr.pdf'))
        
        v_temporal = v_temporal[tp_comp]
        v_templates = v_templates[tp_comp]
        v_spikes = v_spikes[tp_comp]
        v_spatial = v_spatial[tp_comp]
        
        
        n_cells = len(tp_comp)
        v_result = {'F1':[], 'precision':[], 'recall':[]}
        
        for idx in range(n_cells):
            s1 = spikes[idx].flatten()
save_img_folder = '/home/nel/NEL-LAB Dropbox/NEL/Papers/VolPy/manual_annotations/summary_images/comparison_v1.2/'
annotators = sorted(os.listdir(root_folder))
#    select = [0, 1]
for select in [[0,1], [0,2], [1,2]]:
    filenames = sorted(os.listdir(root_folder+annotators[select[0]]))
    result = {}
    #filenames1 = sorted(os.listdir(root_folder+annotators[select[1]]))
    
    for file in filenames:
        img = cm.load(os.path.join(img_folder, file[:-4]+'_summary.tif'))[0]
        dims = img.shape
        mask0 = nf_read_roi_zip(os.path.join(root_folder, annotators[select[0]], file), dims=dims) * 1.
        mask1 = nf_read_roi_zip(os.path.join(root_folder, annotators[select[1]], file), dims=dims) * 1.
        
        tp_gt, tp_comp, fn_gt, fp_comp, performance_cons_off = nf_match_neurons_in_binary_masks(
                mask0, mask1, thresh_cost=0.7, min_dist=10, print_assignment=True,
                plot_results=True, Cn=img, labels=[annotators[select[0]], annotators[select[1]]])
        plt.savefig(os.path.join(save_img_folder, annotators[select[0]][0]+'&'+annotators[select[1]][0]+file[:-4]+'.pdf'))
        plt.close()
        result[file] = performance_cons_off
    
    #%%
    processed = {}
    for i in ['f1_score','recall','precision']:
        #result = eval(i)
        processed[i] = {}    
        for j in ['L1','TEG','HPC']:
            if j == 'L1':
                temp = [result[k][i] for k in result.keys() if 'Fish' not in k and 'IVQ' not in k]
                if i == 'number':
                    processed[i]['L1'] = sum(temp)