All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.github.mianalysis.mia.process.imagej.GaussianFitter Maven / Gradle / Ivy
package io.github.mianalysis.mia.process.imagej;
import org.apache.commons.math3.exception.TooManyEvaluationsException;
import org.apache.commons.math3.fitting.leastsquares.LeastSquaresBuilder;
import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer;
import org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem;
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer;
import org.apache.commons.math3.fitting.leastsquares.MultivariateJacobianFunction;
import org.apache.commons.math3.fitting.leastsquares.ParameterValidator;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.apache.commons.math3.linear.ArrayRealVector;
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.linear.RealVector;
import org.apache.commons.math3.util.Pair;
import ij.process.ImageProcessor;
import io.github.mianalysis.mia.process.math.GaussianDistribution2D;
import io.github.mianalysis.mia.process.math.Indexer;
import io.github.mianalysis.mia.process.math.Validator;
/**
* Created by sc13967 on 05/06/2017.
*/
public class GaussianFitter {
// public static void main(String[] args) {
// new ImageJ();
//
// ImagePlus iplReal = IJ.openImage("C:\\Users\\sc13967\\Desktop\\Crop.tif");
// ImagePlus iplGauss = IJ.createImage("Gauss",iplReal.getWidth(),iplReal.getHeight(),1,8);
// ImageProcessor iprReal = iplReal.getProcessor();
//
//// double x0, double y0, double sx, double sy, double A0, double ABG, double th
// double[] pIn = new double[]{5.0,5.0,5.0,5.0,20.0,7.0,1.0};
// double[][] limits = new double[][]{{0.0,11.0},
// {0.0,11.0},{1.0E-50,1.7976931348623157E308},
// {1.0E-50,1.7976931348623157E308},
// {-1.7976931348623157E308,1.7976931348623157E308},
// {-1.7976931348623157E308,1.7976931348623157E308},
// {0.0,6.283185307179586}};
// int maxEvaluations = 1000;
//
// double[] output = fitGaussian2D(iprReal,pIn,limits,maxEvaluations);
//// double[] output = pIn;
//
// if (output == null) {
// System.err.println("No fit");
// return;
// }
//
// GaussianDistribution2D fitDistribution2D = new GaussianDistribution2D(output[0],output[1],output[2],output[3],output[4],output[5],output[6]);
//
// for (int xPos=0;xPos value(final RealVector p) {
RealVector value = new ArrayRealVector(imagePoints.length);
RealMatrix jacobian = new Array2DRowRealMatrix(imagePoints.length, 7);
double x0 = p.getEntry(0); // centroid x
double y0 = p.getEntry(1); // centroid y
double sx = p.getEntry(2); // sigma x
double sy = p.getEntry(3); // sigma y
double A0 = p.getEntry(4); // peak amplitude
double ABG = p.getEntry(5); // background amplitude
double th = p.getEntry(6); // theta
GaussianDistribution2D distribution2D = new GaussianDistribution2D(x0,y0,sx,sy,A0,ABG,th);
for (int i=0;i(value, jacobian);
}
};