def matchdata_from_exp_and_tp(expname, tp, names): expdata = load_data(expname, names) ifile1, lfile1, pfile1, vfile1 = expdata[tp] ifile2, lfile2, pfile2, vfile2 = expdata[tp + 1] sx1, sy1, sz1 = get_voxel_spacing(vfile1) sx2, sy2, sz2 = get_voxel_spacing(vfile2) celldata1 = celldata.CellData(ifile1, lfile=lfile1) celldata2 = celldata.CellData(ifile2, lfile=lfile2, scale=(sx2 / sy1, sy2 / sy1)) #celldata2 = celldata.CellData(ifile2) #celldata1 = celldata.CellData(ifile1, lfile1) #celldata2 = celldata.CellData(ifile2, lfile2) # until we fix the l number generation try: del (celldata1[1]) del (celldata2[1]) except KeyError: pass mda = matchdata.MatchData(celldata1, celldata2) return mda
def test_matchdata(): ifile1 = 'data/newexp/segmented_image/T05.png' ifile2 = 'data/newexp/segmented_image/T06.png' lfile1 = 'data/newexp/l_numbers/T05.txt' lfile2 = 'data/newexp/l_numbers/T06.txt' celldata1 = celldata.CellData(ifile1, lfile1) celldata2 = celldata.CellData(ifile2, lfile2) del(celldata1[1]) del(celldata2[1]) md = matchdata.MatchData(celldata1, celldata2) v = celldata.Coords2D((8, -36)) md.match_on_restricted_l(8, v) print "On l, matched:", len(md.current_ml) md.set_displacement(v) #md.match_on_centroids_with_area(7) md.match_with_displacement_field(7) print "Initial centroid + area: matched:", len(md.current_ml) #pprint.pprint(md.current_ml) md.match_with_displacement_field(10) print "Local displacement: matched:", len(md.current_ml), "of", len(md.cdfrom) md.match_with_displacement_field(10) print "Local displacement: matched:", len(md.current_ml), "of", len(md.cdfrom) md.match_with_displacement_field(10) print "Local displacement: matched:", len(md.current_ml), "of", len(md.cdfrom) test_divide_tracker(md)
def matchdata_from_exp_and_tp(expname, tp, names): #names = ['Segmented image', 'L numbers', 'Projection'] #names = ['New segmented image', 'L numbers', 'Gaussian projection'] expdata = load_data(expname, names) ifile1, lfile1, pfile1 = expdata[tp] ifile2, lfile2, pfile2 = expdata[tp + 1] celldata1 = celldata.CellData(ifile1) celldata2 = celldata.CellData(ifile2) #celldata1 = celldata.CellData(ifile1, lfile1) #celldata2 = celldata.CellData(ifile2, lfile2) # until we fix the l number generation try: del (celldata1[1]) del (celldata2[1]) except KeyError: pass mda = matchdata.MatchData(celldata1, celldata2) return mda
def test_matchdata2(): expname = 'newexp' tp = 5 names = ['Segmented image', 'L numbers', 'Projection', 'Microscope metadata'] expdata = load_data(expname, names) ifile1, lfile1, pfile1, vfile1 = expdata[tp] ifile2, lfile2, pfile2, vfile2 = expdata[tp + 1] ml = read_ml('data/newexp/matches/T%02dT%02d.match' % (tp, tp + 1)) sx1, sy1, sz1 = get_voxel_spacing(vfile1) sx2, sy2, sz2 = get_voxel_spacing(vfile2) celldata1 = celldata.CellData(ifile1, lfile=lfile1) celldata2 = celldata.CellData(ifile2, lfile=lfile2, scale=(sx2/sy1, sy2/sy1)) md = matchdata.MatchData(celldata1, celldata2) allas = [] for cid in md.get_loby_candidates(): bm = md.lmatrix.best_n_matches(cid, 5) areas = [float(md.cdto[tid].area)/md.cdfrom[cid].area for tid in bm] try: real_m = ml[cid] except KeyError: real_m = [] print cid print bm print real_m print areas for a in areas: allas.append(a) #print sorted(allas)[len(allas)/2], len(allas) pml = {id : md.lmatrix.best_n_matches(id, 5) for id in md.get_loby_candidates()} pprint.pprint(pml) for fid, tids in pml.iteritems(): for tid in tids: delta_a = float(md.cdto[tid].area) / md.cdfrom[fid].area if delta_a < 1.0 or delta_a > 1.7: pml[fid].remove(tid) pprint.pprint(pml) ds = [] for fid, tids in pml.iteritems(): for tid in tids: ds.append(abs(md.cdto[tid].centroid - md.cdfrom[fid].centroid)) med_d = sorted(ds)[len(ds)/3] for fid, tids in pml.iteritems(): for tid in tids: d = abs(md.cdto[tid].centroid - md.cdfrom[fid].centroid) if d > med_d: pml[fid].remove(tid) pprint.pprint(pml) failed = 0 good = 0 for fid in pml: #print fid, try: real_m = ml[fid] except KeyError: real_m = [] if len(real_m) == 1 and len(pml[fid]): if real_m[0] != pml[fid][0]: failed +=1 print 'BAD' else: good += 1 print failed, good, float(good) / (failed + good) #ml = {fid : pml[fid][:1] for fid in pml} ml = md.get_possible_ml() s = random.sample(ml, 5) sd = {k : ml[k] for k in random.sample(ml, 5)} cs = [] for fid, tids in sd.iteritems(): fc = md.cdfrom[fid].centroid tc = md.cdto[tids[0]].centroid cs.append((fc, tc)) #inp = [(f.centroid, msum([t for t in ts]).centroid ) #inp = [(f.centroid, msum([t.centroid for t in ts]) ) # for f, ts in self.itermatches()] center, vd, s = md.calc_iso_params(cs) print md.sampled_iso_params()