public void showresults(String results) { IJ.showStatus(results); IJ.log(results); }
private void fitglobal() { int nparams = 11; int nsel = 0; for (int i = 0; i < ncurves; i++) { if (include[i]) { nsel++; } } double[][] params = new double[nsel][nparams]; String[][] tempformulas = new String[nsel][nparams]; double[][][] constraints = new double[2][nsel][nparams]; int[][] vflmatrix = new int[nsel][nparams]; int counter = 0; for (int i = 0; i < ncurves; i++) { if (include[i]) { for (int j = 0; j < nparams; j++) { params[counter][j] = globalparams[i][j]; tempformulas[counter][j] = globalformulas[i][j]; constraints[0][counter][j] = globalconstraints[0][i][j]; constraints[1][counter][j] = globalconstraints[1][i][j]; vflmatrix[counter][j] = globalvflmatrix[i][j]; } counter++; } for (int j = 0; j < nparams; j++) { undoparams[i][j] = globalparams[i][j]; undoformulas[i][j] = globalformulas[i][j]; undovflmatrix[i][j] = globalvflmatrix[i][j]; } for (int j = 0; j < xpts; j++) { for (int k = 0; k < ypts; k++) { undofit[i][j][k] = fit[i][j][k]; } } undoc2[i] = c2[i]; } undoglobalc2 = globalc2; if (showglobalfitdialog(params, tempformulas, vflmatrix)) { counter = 0; for (int i = 0; i < ncurves; i++) { if (include[i]) { for (int j = 0; j < nparams; j++) { globalparams[i][j] = params[counter][j]; globalformulas[i][j] = tempformulas[counter][j]; globalvflmatrix[i][j] = vflmatrix[counter][j]; } counter++; } } double[] stats = new double[2]; float[][] tempdata = new float[nsel][xpts * ypts]; float[][] tempweights = new float[nsel][xpts * ypts]; counter = 0; for (int i = 0; i < ncurves; i++) { if (include[i]) { for (int j = 0; j < xpts; j++) { for (int k = 0; k < ypts; k++) { tempdata[counter][j + k * xpts] = (float) ((double) pch[i][j][k] / (double) nmeas[i]); tempweights[counter][j + k * xpts] = weights[i][j][k]; } } counter++; } } int tempmaxiter = globalfitclass.maxiter; if (checkc2) { globalfitclass.changemaxiter(0); } double[] tempc2vals = new double[nsel]; IJ.showStatus("Fitting Globally"); float[][] tempfit = globalfitclass.fitdata( params, vflmatrix, tempformulas, paramsnames, constraints, tempdata, tempweights, stats, tempc2vals, false); IJ.showStatus("Fit Complete"); globalfitclass.changemaxiter(tempmaxiter); globalc2 = stats[1]; globalc2label.setText("Global chi^2 = " + (float) globalc2); counter = 0; for (int i = 0; i < ncurves; i++) { if (include[i]) { for (int j = 0; j < xpts; j++) { for (int k = 0; k < ypts; k++) { fit[i][j][k] = tempfit[counter][j + xpts * k] * (float) nmeas[i]; } } if (i == dispcurve) { pwfit.updateSeries(fit[dispcurve], 1, true); } for (int j = 0; j < nparams; j++) { globalparams[i][j] = params[counter][j]; } c2[i] = tempc2vals[counter]; c2array[i].setText("" + (float) c2[i]); counter++; } } float[] temp = pwfit.getLimits(); temp[4] = 1.0f; pwfit.setLimits(temp); } }
public void run(String arg) { ImagePlus imp = WindowManager.getCurrentImage(); Calibration cal = imp.getCalibration(); GenericDialog gd = new GenericDialog("Options"); int subsize = 32; gd.addNumericField("Subregion Size (pixels)?", subsize, 0); int stepsize = 16; gd.addNumericField("Step Size?", stepsize, 0); int shift = 3; gd.addNumericField("STICS temporal Shift?", shift, 0); float xoffset = 0.0f; gd.addNumericField("X_Offset", xoffset, 5, 15, null); float yoffset = 0.0f; gd.addNumericField("Y_Offset", yoffset, 5, 15, null); float multiplier = 8.0f; gd.addNumericField("Velocity Multiplier", multiplier, 5, 15, null); float ftime = 1.0f; gd.addNumericField("Frame_Time(min)", ftime, 5, 15, null); float scaling = (float) cal.pixelWidth; gd.addNumericField("Pixel_Size(um)", scaling, 5, 15, null); boolean norm = true; gd.addCheckbox("Normalize_Vector_lengths?", norm); boolean centered = true; gd.addCheckbox("Center_Vectors?", centered); float magthresh = 0.0f; gd.addNumericField("Magnitude_Threshhold?", magthresh, 5, 15, null); int rlength = 10; gd.addNumericField("Running_avg_length", rlength, 0); int inc = 5; gd.addNumericField("Start_frame_increment", inc, 0); gd.showDialog(); if (gd.wasCanceled()) { return; } subsize = (int) gd.getNextNumber(); stepsize = (int) gd.getNextNumber(); shift = (int) gd.getNextNumber(); xoffset = (float) gd.getNextNumber(); yoffset = (float) gd.getNextNumber(); multiplier = (float) gd.getNextNumber(); ftime = (float) gd.getNextNumber(); scaling = (float) gd.getNextNumber(); norm = gd.getNextBoolean(); centered = gd.getNextBoolean(); magthresh = (float) gd.getNextNumber(); rlength = (int) gd.getNextNumber(); inc = (int) gd.getNextNumber(); int width = imp.getWidth(); int xregions = 1 + (int) (((float) width - (float) subsize) / (float) stepsize); int newwidth = xregions * subsize; int height = imp.getHeight(); int yregions = 1 + (int) (((float) height - (float) subsize) / (float) stepsize); int newheight = yregions * subsize; ImageStack stack = imp.getStack(); int slices = imp.getNSlices(); int channels = imp.getNChannels(); int frames = imp.getNFrames(); if (frames == 1) { frames = slices; slices = 1; } Roi roi = imp.getRoi(); if (roi == null) { roi = new Roi(0, 0, width, height); } STICS_map map = new STICS_map(subsize, stepsize); Object[] tseries = jutils.get3DTSeries(stack, 0, 0, frames, slices, channels); map.update_STICS_map(tseries, width, height, 0, rlength, roi.getPolygon(), shift); FloatProcessor fp = map.get_map(scaling, ftime, stepsize, centered, norm, multiplier, stepsize, magthresh); ImageStack vector_stack = new ImageStack(fp.getWidth(), fp.getHeight()); vector_stack.addSlice("", fp); float[][] vel = map.get_scaled_velocities(scaling, ftime, stepsize); ImageStack velstack = new ImageStack(map.xregions, map.yregions); velstack.addSlice("", vel[0]); velstack.addSlice("", vel[1]); int velframes = 2; IJ.showStatus("frame " + 0 + " calculated"); for (int i = inc; i < (frames - rlength); i += inc) { map.update_STICS_map(tseries, width, height, i, rlength, roi.getPolygon(), shift); FloatProcessor fp2 = map.get_map(scaling, ftime, stepsize, centered, norm, multiplier, stepsize, magthresh); vector_stack.addSlice("", fp2); vel = map.get_scaled_velocities(scaling, ftime, stepsize); velstack.addSlice("", vel[0]); velstack.addSlice("", vel[1]); velframes += 2; IJ.showStatus("frame " + i + " calculated"); } (new ImagePlus("STICS Vectors", vector_stack)).show(); ImagePlus imp3 = new ImagePlus("Velocities", velstack); imp3.setOpenAsHyperStack(true); imp3.setDimensions(2, 1, velframes / 2); new CompositeImage(imp3, CompositeImage.COLOR).show(); }