def constrained_aleks_malis(affs, lbl, threshold=0.5): """ adding constraints for malis weight fill the intracellular space with ground truth when computing merging error fill the boundary with ground truth when computing spliting error """ from cost_fn import constrain_label mbdm, sbdm = constrain_label(bdm, lbl) # get the merger weights mw, mme, mse = aleks_malis(mbdm, lbl) # get the splitter weights sw, sme, sse = aleks_malis(sbdm, lbl) w = mme + sse return (w, mme, sse)
erosion_size = pars['erosion_size'] if erosion_size > 0: print "increase boundary width" erosion_structure = np.ones((erosion_size, erosion_size)) msk = np.copy(lbl > 0) from scipy.ndimage.morphology import binary_erosion msk = binary_erosion(msk, structure=erosion_structure) lbl[msk == False] = 0 print "boundary map: ", bdm return bdm, lbl if __name__ == "__main__": from malis_test import get_params pars = get_params() if pars['is_affinity']: affs, lbl = make_fake_3D_aff(3, 7, 3, 7) else: bdm, lbl = read_image(pars) # normal boundary map and bdm.astype("float64").tofile("../dataset/malis/bdm.bin") lbl.astype('float64').tofile("../dataset/malis/lbl.bin") from cost_fn import constrain_label mbdm, sbdm = constrain_label(bdm, lbl) mbdm.astype("float64").tofile("../dataset/malis/bdm_merge.bin") sbdm.astype("float64").tofile("../dataset/malis/bdm_splite.bin")
# increase boundary width erosion_size = pars['erosion_size'] if erosion_size>0: print "increase boundary width" erosion_structure = np.ones((erosion_size, erosion_size)) msk = np.copy(lbl>0) from scipy.ndimage.morphology import binary_erosion msk = binary_erosion(msk, structure=erosion_structure) lbl[msk==False] = 0 print "boundary map: ", bdm return bdm, lbl if __name__ == "__main__": from malis_test import get_params pars = get_params() if pars['is_affinity']: affs, lbl = make_fake_3D_aff( 3, 7, 3, 7 ) else: bdm, lbl = read_image(pars) # normal boundary map and bdm.astype("float64").tofile("../dataset/malis/bdm.bin") lbl.astype('float64').tofile("../dataset/malis/lbl.bin") from cost_fn import constrain_label mbdm, sbdm = constrain_label(bdm, lbl) mbdm.astype("float64").tofile("../dataset/malis/bdm_merge.bin") sbdm.astype("float64").tofile("../dataset/malis/bdm_splite.bin")