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): 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_overall_centroid(): ifile = 'data/newexp/segmented_image/T00.png' ifile2 = 'data/newexp/segmented_image/T01.png' cd = celldata.CellData(ifile) cd2 = celldata.CellData(ifile2) print "Loaded celldata" sys.stdout.flush() #all = sum(cd.cells, celldata.Cell([])) #allpl = [c.pl for c in cd.cells] #myl = list(itertools.chain.from_iterable(allpl)) #xs, ys = zip(*myl) #print sum(xs) / len(xs), sum(ys) / len(ys) print cd.center print cd2.center
def main(): #try: # image_file1 = sys.argv[1] # image_file2 = sys.argv[2] #except: # print "Usage %s image_file1 image_file2" % os.path.basename(sys.argv[0]) # sys.exit(0) 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) md = MatchData(celldata1, celldata2) print md.best_matches_on_l(15, 1)
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_for_ls(image_file, l_file): ln = lnumbers.parse_l_file(l_file) cd = celldata.CellData(image_file) lkeys = set(ln.keys()) ckeys = set(cd.keys()) unique_to_l = list((lkeys | ckeys) - ckeys) unique_to_c = list((lkeys | ckeys) - lkeys) if len(unique_to_c) or len(unique_to_l): print "For %s/%s" % (image_file, l_file) if len(unique_to_c): print " Unique to data from image file:", unique_to_c if len(unique_to_l): print " Unique to data from l file:", unique_to_l
def test_centroid_summer(): ifile = 'data/newexp/segmented_image/T05.png' cd = celldata.CellData(ifile) cells = [cd[150], cd[151], cd[152]] for c in cells: print c.centroid() #print cells[0].pl + cells[1].pl tpl = sum([c.pl for c in cells], []) xs, ys = zip(*tpl) x, y = sum(xs) / len(tpl), sum(ys) / len(tpl) print Coords2D((x, y)) #newcell = cells[0] + cells[1] + cells[2] newcell = sum(cells, celldata.Cell([])) print newcell.centroid()
def test_l_numbers(): 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] celldata1 = celldata.CellData(ifile1, lfile=lfile1) #celldata2 = celldata.CellData(ifile2, lfile=lfile2) #md = matchdata.MatchData(celldata1, celldata2) #print md.lmatrix.best_match(515) lm = lnumbers.LMatrix.from_files(lfile1, lfile2) #for id, vals in lm.ln1.iteritems(): # print id, lm.best_n_matches(id, 5), sum(vals[5:9]) lobiness = [(id, sum(vals[6:11])) for id, vals in lm.ln1.iteritems()] slobi = sorted(lobiness, key=itemgetter(1)) blobi = slobi[-45:-5] ml = read_ml('data/newexp/matches/T%02dT%02d.match' % (tp, tp + 1)) ts = 0 for id, score in blobi: try: real_m = ml[id] except KeyError: real_m = [] bm = lm.best_n_matches(id, 5) success = False for m in real_m: if m in bm: success = True ts += 1 print id, score, bm, real_m, success print ts print zip(*blobi)[0]
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()
def test_smarter_centroid(): ifile = 'data/newexp/segmented_image/T05.png' cd = celldata.CellData(ifile) print cd[150].centroid
def run(self): self.celld = celldata.CellData(self.ifile)