def fit_gauss(lroi, imp, p, peak_id, id_, type_, rm): lroi.setName("{}_{}_{}".format(str(id_), peak_id, type_)) imp.setRoi(lroi) rm.addRoi(lroi) prof = ProfilePlot(imp) y = prof.getProfile() x = xrange(len(y)) fitter = CurveFitter(x, y) fitter.doFit(CurveFitter.GAUSSIAN) param_values = fitter.getParams() std = param_values[3] fwhm = 2.3548 * std r2 = fitter.getFitGoodness() y_ = [fitter.f(x_) for x_ in x] area_profile = sum(y) - len(y) *min(y) area_gauss = sum(y_) - len(y_)*min(y_) output = {} output["x_pos"] = p.x output["y_pos"] = p.y output["fwhm"] = fwhm output["fwhm_nm"] = pixel_size_nm * fwhm output["r2_GoF"] = r2 output["id"] = id_ output["peak_id"] = peak_id output["type"] = type_ # yai, excel maagic :-) output["avg_fwhm"] = '=AVERAGEIFS(F:F,B:B,B{},F:F,"<>"&"")'.format(id_+2) output["area_profile"] = area_profile output["area_gauss"] = area_gauss if peak_id == DEBUG: plot = Plot("ROI peak {} type {}".format(peak_id, type_), "X (gray)", "Y (fit window)") plot.setLineWidth(2) plot.setColor(Color.RED) plot.addPoints(x, y, Plot.LINE) plot.setColor(Color.BLUE) plot.addPoints(x, y_, Plot.LINE) plot.show() return output
cv = CurveFitter([a[0] for a in spshifts], [8 - a[1] for a in spshifts]) # fit the distortion measurements cv.doFit(CurveFitter.EXP_WITH_OFFSET) # cv.doFit(CurveFitter.EXPONENTIAL) # cv.doFit(CurveFitter.POLY2) # cv.doFit(CurveFitter.POLY3) plot = cv.getPlot() plot.show() 8 / 0 plot_images.append(plot.getImagePlus()) IJ.log('sFOV ' + str(sFOV)) IJ.log('fitGoodness ' + str(cv.getFitGoodness())) IJ.log('formula ' + str(cv.getFormula())) fit_params = cv.getParams() IJ.log('fit_params' + str(fit_params)) # write the fit results to file g.write('sFOV\t' + str(sFOV) + '\t' + 'a\t' + str(fit_params[0]) + '\t' + 'b\t' + str(fit_params[1]) + '\t' + 'c\t' + str(fit_params[2]) + '\t' + 'formula\t' + str(cv.getFormula()) + '\t' + 'fitGoodness\t' + str(cv.getFitGoodness()) + '\n') # # # # # The following commented code applies a scan correction using bigwarp. # # # # # A grid of landmarks is generated, saved into bigwarp format, then applied. # # # # # It is slow and needs to be optimized.