def fit_curve(x, y):
    """fits curve of a single gaussian, returns
	FWHM, R^2, and the fn args.
	"""
    cf = CurveFitter(x, y)
    cf.doFit(12)
    params = cf.getResultString()
    fwhm, r2 = getFWHM(params)
    return fwhm, r2, params
Exemplo n.º 2
0
# 	http://hyperphysics.phy-astr.gsu.edu/hbase/math/gaufcn2.html

import ij.measure.CurveFitter

imp = IJ.getImage()
prof = ProfilePlot(imp)
curprofile = prof.getProfile()
print(len(curprofile));
#for i in curprofile:
#	print(i)

pixx = range(len(curprofile))
fitA = range(len(curprofile))

cf = CurveFitter(pixx, curprofile)
cf.doFit(cf.GAUSSIAN)
#print(cf.getFormula())
print(cf.getResultString())

cfp = cf.getParams()
EstimatedDiameter = "Diameter = " + str(2.355*cfp[3])
IJ.log(EstimatedDiameter)

for i in range(len(curprofile)):
	fitA[i] = cf.f(cfp, i)
fitplot = Plot("fitted", "pixels", "intensity", pixx, fitA)
fitplot.addPoints(pixx, curprofile, fitplot.CIRCLE)
fitplot.addLabel(0.1, 0.1, EstimatedDiameter)
fitplot.show()

from array import array
from ij import IJ
from ij.measure.CurveFitter import *

# Example from
# http://rsbweb.nih.gov/ij/macros/examples/CurveFittingDemo.txt
# x = array('d', [0, 1, 2, 3, 4, 5])
# y = array('d', [0, 0.9, 4.5, 8, 18, 24])
#
# make one where I know approximate coefficients
x = array("d", [0, 1, 2, 3, 4, 5])
y = array("d", [0, 1.1, 1.9, 2.95, 4.02, 4.99])
cf = CurveFitter(x, y)
cf.doFit(STRAIGHT_LINE)
res = cf.getParams()
# N.B. cf.getParams() returns
# [ intercept, slope, sum of square residuals]
b = res[0]
m = res[1]
p3 = res[2]
print "Linear fit example: b=" + IJ.d2s(b, 6) + ", m =" + IJ.d2s(m, 6) + ", par3=" + IJ.d2s(p3, 6)
print cf.getResultString()
Exemplo n.º 4
0
normalized_curve = []
for i in range(n_slices):
    normalized_curve.append( (If[i] - min_intensity) / (mean_If - min_intensity)   *   mean_In / In[i] )
     
x = [i * frame_interval for i in range( n_slices ) ] 
y = normalized_curve
 
xtofit = [ i * frame_interval for i in range( n_slices - bleach_frame ) ]
ytofit = normalized_curve[ bleach_frame : n_slices ]
  
# Fitter
fitter = CurveFitter(xtofit, ytofit)
fitter.doFit(CurveFitter.EXP_RECOVERY_NOOFFSET)
IJ.log("Fit FRAP curve by " + fitter.getFormula() )
param_values = fitter.getParams()
IJ.log( fitter.getResultString() )
  
# Overlay fit curve, with oversampling (for plot)
xfit = [ (t / 10.0  + bleach_frame) * frame_interval for t in range(10 * len(xtofit) ) ]
yfit = []
for xt in xfit:
    yfit.append( fitter.f( fitter.getParams(), xt - xfit[0]) )
 
  
plot = Plot("Normalized FRAP curve for " + current_imp.getTitle(), "Time ("+time_units+')', "NU", [], [])
plot.setLimits(0, max(x), 0, 1.5 );
plot.setLineWidth(2)
 
 
plot.setColor(Color.BLACK)
plot.addPoints(x, y, Plot.LINE)