use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class MeasureTrackMotion method calculateSpatialMeasurements.
public static void calculateSpatialMeasurements(Obj trackObject, Track track, boolean averageSubtracted) {
if (track.size() == 0) {
// Adding measurements to track objects
String name = getFullName(Measurements.EUCLIDEAN_DISTANCE_PX, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.EUCLIDEAN_DISTANCE_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.TOTAL_PATH_LENGTH_PX, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.TOTAL_PATH_LENGTH_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.DIRECTIONALITY_RATIO, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
} else {
// If the track has a single time-point there's no velocity to measure
double distPerPxXY = trackObject.getDppXY();
double euclideanDistance = track.getEuclideanDistance();
double totalPathLength = track.getTotalPathLength();
String name = getFullName(Measurements.EUCLIDEAN_DISTANCE_PX, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, euclideanDistance));
name = getFullName(Measurements.EUCLIDEAN_DISTANCE_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, euclideanDistance * distPerPxXY));
name = getFullName(Measurements.TOTAL_PATH_LENGTH_PX, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, totalPathLength));
name = getFullName(Measurements.TOTAL_PATH_LENGTH_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, totalPathLength * distPerPxXY));
name = getFullName(Measurements.DIRECTIONALITY_RATIO, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, track.getDirectionalityRatio()));
}
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class FitLongestChord method processObject.
public void processObject(Obj object, boolean measureWidth, boolean measureOrientation, boolean storeEndPoints) {
double dppXY = object.getDppXY();
LongestChordCalculator calculator = new LongestChordCalculator(object);
double longestChordLength = calculator.getLCLength();
object.addMeasurement(new Measurement(Measurements.LENGTH_PX, longestChordLength));
object.addMeasurement(new Measurement(Measurements.LENGTH_CAL, longestChordLength * dppXY));
if (storeEndPoints) {
double[][] LC = calculator.getLC();
object.addMeasurement(new Measurement(Measurements.X1_PX, LC[0][0]));
object.addMeasurement(new Measurement(Measurements.Y1_PX, LC[0][1]));
object.addMeasurement(new Measurement(Measurements.Z1_SLICE, LC[0][2]));
object.addMeasurement(new Measurement(Measurements.X2_PX, LC[1][0]));
object.addMeasurement(new Measurement(Measurements.Y2_PX, LC[1][1]));
object.addMeasurement(new Measurement(Measurements.Z2_SLICE, LC[1][2]));
}
if (measureWidth) {
CumStat cumStat = calculator.calculateAverageDistanceFromLC();
if (cumStat == null) {
object.addMeasurement(new Measurement(Measurements.MEAN_SURF_DIST_PX, Double.NaN));
object.addMeasurement(new Measurement(Measurements.MEAN_SURF_DIST_CAL, Double.NaN));
object.addMeasurement(new Measurement(Measurements.STD_SURF_DIST_PX, Double.NaN));
object.addMeasurement(new Measurement(Measurements.STD_SURF_DIST_CAL, Double.NaN));
object.addMeasurement(new Measurement(Measurements.MAX_SURF_DIST_PX, Double.NaN));
object.addMeasurement(new Measurement(Measurements.MAX_SURF_DIST_CAL, Double.NaN));
} else {
object.addMeasurement(new Measurement(Measurements.MEAN_SURF_DIST_PX, cumStat.getMean()));
object.addMeasurement(new Measurement(Measurements.MEAN_SURF_DIST_CAL, cumStat.getMean() * dppXY));
object.addMeasurement(new Measurement(Measurements.STD_SURF_DIST_PX, cumStat.getStd()));
object.addMeasurement(new Measurement(Measurements.STD_SURF_DIST_CAL, cumStat.getStd() * dppXY));
object.addMeasurement(new Measurement(Measurements.MAX_SURF_DIST_PX, cumStat.getMax()));
object.addMeasurement(new Measurement(Measurements.MAX_SURF_DIST_CAL, cumStat.getMax() * dppXY));
}
}
if (measureOrientation) {
double orientationDegs = Math.toDegrees(calculator.getXYOrientationRads());
// Ensuring the orientation is positive
while (orientationDegs < 0) orientationDegs += 360;
// Fitting to range -90 to + 90 degrees
orientationDegs = (orientationDegs + 90) % 180 - 90;
object.addMeasurement(new Measurement(Measurements.ORIENTATION_XY_DEGS, orientationDegs));
}
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class GetLocalObjectRegion method getCentroid.
protected int[] getCentroid(Obj inputObject) {
String centroidSource = parameters.getValue(CENTROID_SOURCE);
double xPosition = parameters.getValue(X_POSITION);
double yPosition = parameters.getValue(Y_POSITION);
double zPosition = parameters.getValue(Z_POSITION);
String xMeasurementName = parameters.getValue(X_MEASUREMENT);
String yMeasurementName = parameters.getValue(Y_MEASUREMENT);
String zMeasurementName = parameters.getValue(Z_MEASUREMENT);
String centroidParentObjectsName = parameters.getValue(PARENT_OBJECT_FOR_CENTROID);
String centroidUnits = parameters.getValue(CENTROID_SPATIAL_UNITS);
if (inputObject.is2D())
zPosition = 0;
switch(centroidSource) {
case CentroidSources.MEASUREMENT:
Measurement xMeasurement = inputObject.getMeasurement(xMeasurementName);
Measurement yMeasurement = inputObject.getMeasurement(yMeasurementName);
Measurement zMeasurement = inputObject.getMeasurement(zMeasurementName);
if (xMeasurement == null || yMeasurement == null || (!inputObject.is2D() && zMeasurement == null))
return null;
xPosition = xMeasurement.getValue();
yPosition = yMeasurement.getValue();
if (!inputObject.is2D())
zPosition = zMeasurement.getValue();
break;
case CentroidSources.OBJECT_CENTROID:
xPosition = inputObject.getXMean(true);
yPosition = inputObject.getYMean(true);
if (!inputObject.is2D())
zPosition = inputObject.getZMean(true, false);
break;
case CentroidSources.PARENT_MEASUREMENT:
Obj parentObject = inputObject.getParent(centroidParentObjectsName);
if (parentObject == null)
return null;
else {
xMeasurement = parentObject.getMeasurement(xMeasurementName);
yMeasurement = parentObject.getMeasurement(yMeasurementName);
zMeasurement = parentObject.getMeasurement(zMeasurementName);
if (xMeasurement == null || yMeasurement == null || (!inputObject.is2D() && zMeasurement == null))
return null;
xPosition = xMeasurement.getValue();
yPosition = yMeasurement.getValue();
if (!inputObject.is2D())
zPosition = zMeasurement.getValue();
}
break;
}
switch(centroidUnits) {
case SpatialUnits.CALIBRATED:
xPosition = xPosition / inputObject.getDppXY();
yPosition = yPosition / inputObject.getDppXY();
if (!inputObject.is2D())
zPosition = zPosition / inputObject.getDppXY();
break;
}
return new int[] { (int) Math.round(xPosition), (int) Math.round(yPosition), (int) Math.round(zPosition) };
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class FitGaussian2D method assignMeasurements.
static void assignMeasurements(Obj obj, ImageProcessor iprCrop, double[] p, int x, int y, int halfW) {
double distPerPxXY = obj.getDppXY();
double distPerPxZ = obj.getDppZ();
double x0 = p[0] + x - halfW;
double y0 = p[1] + y - halfW;
double z0 = obj.getZMean(true, false);
double sx = p[2];
double sy = p[3];
double A0 = p[4];
double ABG = p[5];
double th = p[6];
double residual = calculateResidual(iprCrop, p);
double ellipticity = sx > sy ? (sx - sy) / sx : (sy - sx) / sy;
double sm = (sx + sy) / 2;
// Storing the results as measurements
obj.addMeasurement(new Measurement(Measurements.X0_PX, x0));
obj.addMeasurement(new Measurement(Measurements.Y0_PX, y0));
obj.addMeasurement(new Measurement(Measurements.Z0_SLICE, z0));
obj.addMeasurement(new Measurement(Measurements.SIGMA_X_PX, sx));
obj.addMeasurement(new Measurement(Measurements.SIGMA_Y_PX, sy));
obj.addMeasurement(new Measurement(Measurements.SIGMA_MEAN_PX, sm));
obj.addMeasurement(new Measurement(Measurements.X0_CAL, x0 * distPerPxXY));
obj.addMeasurement(new Measurement(Measurements.Y0_CAL, y0 * distPerPxXY));
obj.addMeasurement(new Measurement(Measurements.Z0_CAL, z0 * distPerPxZ));
obj.addMeasurement(new Measurement(Measurements.SIGMA_X_CAL, sx * distPerPxXY));
obj.addMeasurement(new Measurement(Measurements.SIGMA_Y_CAL, sy * distPerPxXY));
obj.addMeasurement(new Measurement(Measurements.SIGMA_MEAN_CAL, sm * distPerPxXY));
obj.addMeasurement(new Measurement(Measurements.A_0, A0));
obj.addMeasurement(new Measurement(Measurements.A_BG, ABG));
obj.addMeasurement(new Measurement(Measurements.THETA, th));
obj.addMeasurement(new Measurement(Measurements.ELLIPTICITY, ellipticity));
obj.addMeasurement(new Measurement(Measurements.RESIDUAL, residual));
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class FitGaussian2D method assignMissingMeasurements.
static void assignMissingMeasurements(Obj obj) {
obj.addMeasurement(new Measurement(Measurements.X0_PX, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.Y0_PX, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.Z0_SLICE, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.SIGMA_X_PX, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.SIGMA_Y_PX, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.SIGMA_MEAN_PX, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.X0_CAL, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.Y0_CAL, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.Z0_CAL, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.SIGMA_X_CAL, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.SIGMA_Y_CAL, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.SIGMA_MEAN_CAL, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.A_0, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.A_BG, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.THETA, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.ELLIPTICITY, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.RESIDUAL, Double.NaN));
}
Aggregations