def pltImAndCoords(h5file, frame, coordFiles, printerFriendly=True): '''read image coordinates, plot them together with the raw data save output as .png or .tiff or display with matplotlib''' # read input data rawData = h5.readHDF5Frame(h5file, frame) coordDat = [(coord2im.readCoordsFile(f)) for f in coordFiles] if printerFriendly: rawData = -rawData plt.imshow(rawData, interpolation='nearest') plt.colorbar() plt.gray() axx = plt.axis() markers = ['r+', 'bx', 'go', 'k,', 'co', 'yo'] for i in range(len(coordFiles)): c, w, h = coordDat[i] cc = np.array(c) idxs = (cc[:,2] == frame) cc = cc[idxs] ll = coordFiles[i][coordFiles[i].rfind('/')+1:] plt.plot(cc[:,0], cc[:,1], markers[i], label=ll) plt.legend() plt.axis(axx) # dont change axis by plotting coordinates plt.show()
path = r'/net/gorgonzola/storage/jschleic/Documents/log/vigra-storm-cpp/' files = [ #'20a_MT_Atto520-coords.txt', '20a_MT_Atto520-coords-nofilter-thr800.txt', '20a_MT_Atto520-coords-wiener-thr800.txt', '20a_MT_Atto520-coords-invansc-thr800.txt', '20a_MT_Atto520-coords-luisier_analyze75-thr800.txt', '20a_MT_Atto520-coords-wiener-thr800-CatmullRom.txt', '20a_MT_Atto520-coords-rapidstorm.txt', 'tmp.txt', '20a_MT_Atto520-coords-wiener-thr800-CMR-Ortsraumfilter.txt' ] # Overview plot (whole image) plt.figure(1) overviewfile = files[1] coords = coordsToImage.readCoordsFile(path + overviewfile) plt.title("Storm image: " + overviewfile) roi = [77, 91, 72, 82] #~ 89,105,44,62 #~ roi = [91,105,14,33 ] # roi rectangle mybox = np.array([[roi[0], roi[0], roi[1], roi[1], roi[0]], [roi[2], roi[3], roi[3], roi[2], roi[2]]]) if 0: coordsToImage.plot_coords(coords) # plot roi as rectangle plt.plot(mybox[0, ...], mybox[1, ...], '0.3') else:
x, y, intensity = p nearestIdx = 0 #initial guess nearestDist = 32768 #large number for i in range(len(beads)): if not x - maxDist <= beads[i][0][0] <= x + maxDist: continue if not y - maxDist <= beads[i][0][1] <= y + maxDist: continue #check nearest neighbor if dist(beads[i][0], p) < nearestDist: nearestIdx = i nearestDist = dist(beads[i][0], p) return nearestDist, nearestIdx cc, a, b = coord2im.readCoordsFile(filename) beads = [] ign = 0 # sort beads in 'bins' for x, y, frame, intensity, z in cc: if frame == 0: #define bins nearestDist, nearestIdx = nearestNeighbor((x, y, intensity), beads, maxDist) if nearestDist > maxDist: beads.append([(x, y, intensity)]) else: print "removing beads too close together: ", ( x, y, intensity), beads[nearestIdx] beads.remove(beads[nearestIdx]) else:
def nearestNeighbor(p, beads, maxDist): x,y,intensity = p nearestIdx = 0 #initial guess nearestDist = 32768 #large number for i in range(len(beads)): if not x-maxDist <= beads[i][0][0] <= x+maxDist: continue if not y-maxDist <= beads[i][0][1] <= y+maxDist: continue #check nearest neighbor if dist(beads[i][0], p)<nearestDist: nearestIdx = i nearestDist = dist(beads[i][0], p) return nearestDist, nearestIdx cc, a, b = coord2im.readCoordsFile(filename) beads = [] ign=0 # sort beads in 'bins' for x, y, frame, intensity, z in cc: if frame==0: #define bins nearestDist, nearestIdx = nearestNeighbor((x,y,intensity), beads, maxDist) if nearestDist > maxDist: beads.append([(x,y,intensity)]) else: print "removing beads too close together: ", (x,y,intensity), beads[nearestIdx] beads.remove(beads[nearestIdx]) else: nearestDist, nearestIdx = nearestNeighbor((x,y,intensity), beads, maxDist) if nearestDist>maxDist: # no bin found