def detectBeadsFromFile(filename, cutoff,  maxDist=2,maxStdDev=1.1):
	dims, cc = coord2im.readfile(filename)
	import time
	start = time.time()
	beadMeans, beadScatter = detectBeads(dims, cc, cutoff,maxDist, maxStdDev)
	print "calculated in %f seconds" % (time.time()-start)
	return beadMeans
Ejemplo n.º 2
0
    def getCircledBead(
        self, layer
    ):  # returns the bead (layer=0 for red, layer=1 for green) in the rectangular selected by single mouseclick
        listItem = self.ui.fileWidget.item(layer)
        filename = listItem.data(QtCore.Qt.DisplayRole).toString()
        dims, cc = coords.readfile(filename)
        rect = CursorGraphicsScene.getCursorPosition(self.scene)
        maxDist = CursorGraphicsScene.cursorRadius(self.scene)
        roi = [rect[0] - maxDist, rect[0] + maxDist, rect[1] - maxDist, rect[1] + maxDist]
        candidate = coords.cropROI(cc, roi)[:, :4]

        if len(candidate) < self.cutoff * dims[2]:
            print "Number of points below percentage of occurrency 2"
            bead = "false"
        else:
            mm, stddev, intensitiy = beadLocalisation.beadVariance(candidate)
            color = QtGui.QColor.fromRgbF(*self.m_colors[layer])
            bead = BeadCircle(mm[0], mm[1], color, layer)
        if len(candidate) > dims[2]:
            print " WARNING: Number of points below percentage of occurrency because len(candidate) =%d > dims[2] = %d" % (
                len(candidate),
                dims[2],
            )
            # bead='false'
        return bead
Ejemplo n.º 3
0
def loadImage(filename, color=(1.,1.,0.), factor=4):
	print "reading file %s" % filename
	
	dims, cc = coords.readfile(filename)
	img = coords.coords2Image(dims, cc, factor=factor)
	colorimg = np.zeros((img.shape[0],img.shape[1],4),dtype=np.uint8)
	mx = np.max(img)
	colorimg[:,:,0] = color[2]*img*(255./mx) # blue = LSB
	colorimg[:,:,1] = color[1]*img*(255./mx) # green
	colorimg[:,:,2] = color[0]*img*(255./mx) # red

	return colorimg, cc, dims
Ejemplo n.º 4
0
	def exportTransformedCoordinates_triggered(self):
		'''export coordinate file list of tranformed points for all layers'''
		for i in xrange(1,self.ui.fileWidget.count()):
			listItem = self.ui.fileWidget.item(i)
			filename = listItem.data(QtCore.Qt.DisplayRole).toString()
			name = QtCore.QFileInfo(filename).fileName() # without path
			newfilename = QtGui.QFileDialog.getSaveFileName(self.main_window, "Save Coordinate List %s" % name, filter="Coordinate List (*.txt)")
			if not newfilename.contains('.'):
				newfilename += ".txt" # add default extension
			dimensions, points = coords.readfile(filename)
			p_transformed = self.transformcontroller.doTransform(points[:,0:2], i)
			points[:,0:2] = p_transformed
			coords.writefile(newfilename, dimensions[0:2], points)
Ejemplo n.º 5
0
	plt.figure()
	plt.plot(coords[:,0], coords[:,1], 'b,')
	plt.plot(inliers[:,0], inliers[:,2], 'rx')
	plotLine(fit, roi[0], roi[1])
	
	
if __name__ == "__main__":
	path = r'./'
	files = [ # list of files to compare
			'20a_MT_Atto520-coords-HCI.txt']
	roi = [77,91,72,82]
	#~ roi = [91,105,14,33 ]

	# Overview plot (whole image)
	overviewfile=files[0]
	dims, coords = cr.readfile(path+overviewfile)
	plt_overview(dims, coords, roi)

	for f in files:
		print "processing file " + f
		dims, coords = cr.readfile(path+f)
		coords = cr.cropROI(coords, roi)
		linewidth, inliers, fitparams = lw.robust_measure(coords)
		print np.sqrt(linewidth)

		#Plot data
		plt_fit(coords, inliers, roi, fitparams)
		plt.title("Data: " + f)
		plt.axis(roi)
		
		#plot residuals histogram
	return np.array(cleanmm)

def detectBeadsFromFile(filename, cutoff,  maxDist=2,maxStdDev=1.1):
	dims, cc = coord2im.readfile(filename)
	import time
	start = time.time()
	beadMeans, beadScatter = detectBeads(dims, cc, cutoff,maxDist, maxStdDev)
	print "calculated in %f seconds" % (time.time()-start)
	return beadMeans

if __name__ == "__main__":
	if len(sys.argv != 2):
		print "Usage: %s coordsfile.txt" % sys.argv[0]
		sys.exit(1)
	filename = sys.argv[1]
	dims, cc = coord2im.readfile(filename)
	beadMeans, beadScatter = detectBeads(dims, cc)

	print "number of beads: ", len(beadMeans)
	#~ print singleConsidered, "single detections considered."
	#~ print skipped, "beads skipped."
	print "mean variance: %f" % (np.mean(beadScatter, axis=0)[1])

	#plot:
	import matplotlib.pyplot as plt
	xx,yy=np.hsplit(np.array(beadScatter),np.array([1]))
	plt.plot(xx,yy,'rx')
	plt.xlabel('Beat Intensity')
	plt.ylabel('stddev of detected position')
	plt.title('STORM: localisation precision at different beat intensities')
	plt.ylabel('stddev of detected position')
Ejemplo n.º 7
0
    parametersX = myoutputX.res_var
    parametersY = myoutputY.res_var

    return [parametersX, parametersY]

# if run standalone
if __name__ == "__main__":
    import matplotlib.pyplot as plt
    import coords
    import scipy
    file1 = 'data/HeLa5_10000z_3_polyL_actinmEOS2-steve.txt'
    file1_landmarks = 'data/HeLa5_10000z_3_polyL_actinmEOS2-steve.txt_beads.txt'
    file2 = 'data/HeLa5_10000z_3_polyL_ER647.txt'
    file2_landmarks = 'data/HeLa5_10000z_3_polyL_ER647.txt_beads.txt'

    thrash, landmarks1 = coords.readfile(file1_landmarks)
    thrash, landmarks2 = coords.readfile(file2_landmarks)
    landmarks1 = landmarks1[:,:2]
    landmarks2 = landmarks2[:,:2]
    trafo = affineMatrix2DFromCorrespondingPoints(landmarks2, landmarks1)
    print("Transformation: \n", trafo)

    dims, cc1 = coords.readfile(file1)
    dims, cc2 = coords.readfile(file2)
    cc2_ones = np.hstack([cc2[:,:2], np.ones((len(cc2),1))]) # add column with ones for affine trafo
    cc2_transformed = np.dot(cc2_ones, trafo.T)[:,:2]
    cc2_transformed = np.hstack([cc2_transformed,cc2[:,2:]]) # add intensity information again

    im1 = coords.coords2Image(dims, cc1)
    im2 = coords.coords2Image(dims, cc2_transformed)
Ejemplo n.º 8
0
    ws[ws < threshold] = 0
    legalIndices = np.nonzero(ws)
    legalPairs = np.array(d)[legalIndices]
    return legalPairs

def robust_measure(coords):
	xs = coords[:,0]
	ys = coords[:,1]
	ll = len(coords)
	fit = robreg.lmrob(xs,ys)
	all_data = np.hstack( [xs.reshape([ll,1]),np.ones((ll,1)),ys.reshape([ll,1])] )
	inliers = remove_outliers(all_data, fit)
	bestfit = np.array([[fit['a']],[fit['b']]])
	
	model = AffineLinearModel()
	resids = model.get_error(inliers, bestfit)
	estimLWPercentile = scipy.stats.scoreatpercentile(resids, 95)
	return estimLWPercentile, inliers, bestfit

if __name__ == "__main__":
	if not len(sys.argv) == 6:
		print ( "Usage: " + sys.argv[0] + "coordsfile.txt xmin xmax ymin ymax")
		sys.exit(1)
	filename = sys.argv[1]
	roi = [int(sys.argv[j]) for j in range(2,6)]
	dimensions, coords = cr.readfile(filename)
	coords = cr.cropROI(coords, roi)
	lw, inl, fit = robust_measure(coords)
	print filename, np.sqrt(lw)
	
Ejemplo n.º 9
0

def robust_measure(coords):
    xs = coords[:, 0]
    ys = coords[:, 1]
    ll = len(coords)
    fit = robreg.lmrob(xs, ys)
    all_data = np.hstack(
        [xs.reshape([ll, 1]),
         np.ones((ll, 1)),
         ys.reshape([ll, 1])])
    inliers = remove_outliers(all_data, fit)
    bestfit = np.array([[fit['a']], [fit['b']]])

    model = AffineLinearModel()
    resids = model.get_error(inliers, bestfit)
    estimLWPercentile = scipy.stats.scoreatpercentile(resids, 95)
    return estimLWPercentile, inliers, bestfit


if __name__ == "__main__":
    if not len(sys.argv) == 6:
        print("Usage: " + sys.argv[0] + "coordsfile.txt xmin xmax ymin ymax")
        sys.exit(1)
    filename = sys.argv[1]
    roi = [int(sys.argv[j]) for j in range(2, 6)]
    dimensions, coords = cr.readfile(filename)
    coords = cr.cropROI(coords, roi)
    lw, inl, fit = robust_measure(coords)
    print filename, np.sqrt(lw)