use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class TrackObjects method linkObjects.
public static void linkObjects(Obj prevObj, Obj currObj, String trackObjectsName) {
// Getting the track object from the previous-frame object
Obj track = prevObj.getParent(trackObjectsName);
// Setting relationship between the current object and track
track.addChild(currObj);
currObj.addParent(track);
// Adding partner relationships between adjacent points in the track
prevObj.addPartner(currObj);
currObj.addPartner(prevObj);
// Adding references to each other
prevObj.addMeasurement(new Measurement(Measurements.TRACK_NEXT_ID, currObj.getID()));
currObj.addMeasurement(new Measurement(Measurements.TRACK_PREV_ID, prevObj.getID()));
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class ExtractObjectCrossSection method process.
@Override
public Status process(Workspace workspace) {
// Getting input objects
String inputObjectsName = parameters.getValue(INPUT_OBJECTS);
Objs inputObjects = workspace.getObjects().get(inputObjectsName);
// Getting parameters
String outputObjectsName = parameters.getValue(OUTPUT_OBJECTS);
String referenceMode = parameters.getValue(REFERENCE_MODE);
String imageForMeasurementName = parameters.getValue(IMAGE_FOR_MEASUREMENT);
String imageMeasurementName = parameters.getValue(IMAGE_MEASUREMENT);
String objectMeasurementName = parameters.getValue(OBJECT_MEASUREMENT);
String indicesString = parameters.getValue(RELATIVE_SLICE_INDICES);
Objs outputObjects = new Objs(outputObjectsName, inputObjects);
workspace.addObjects(outputObjects);
int[] indices = CommaSeparatedStringInterpreter.interpretIntegers(indicesString, true, inputObjects.getNSlices());
// same for all objects
switch(referenceMode) {
case ReferenceModes.IMAGE_MEASUREMENT:
Image imageForMeasurement = workspace.getImage(imageForMeasurementName);
Measurement imageMeasurement = imageForMeasurement.getMeasurement(imageMeasurementName);
indices = applyIndexOffset(indices, imageMeasurement);
break;
}
for (Obj inputObject : inputObjects.values()) {
int[] finalIndices = indices;
switch(referenceMode) {
case ReferenceModes.OBJECT_MEASUREMENT:
Measurement objectMeasurement = inputObject.getMeasurement(objectMeasurementName);
finalIndices = applyIndexOffset(indices, objectMeasurement);
break;
}
process(inputObject, outputObjects, finalIndices);
}
if (showOutput)
outputObjects.convertToImageRandomColours().showImage();
return Status.PASS;
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class MeasureTrackMotion method calculateInstantaneousVelocity.
public static void calculateInstantaneousVelocity(Obj trackObject, Track track, String inputSpotObjectsName, boolean averageSubtracted) {
double distPerPxXY = trackObject.getDppXY();
double distPerPxZ = trackObject.getDppZ();
TreeMap<Integer, Double> xVelocity = track.getInstantaneousXVelocity();
TreeMap<Integer, Double> yVelocity = track.getInstantaneousYVelocity();
TreeMap<Integer, Double> zVelocity = track.getInstantaneousZVelocity();
TreeMap<Integer, Double> speed = track.getInstantaneousSpeed();
// Getting the first timepoint
int minT = Integer.MAX_VALUE;
for (Obj spotObject : trackObject.getChildren(inputSpotObjectsName).values()) {
minT = Math.min(minT, spotObject.getT());
}
for (Obj spotObject : trackObject.getChildren(inputSpotObjectsName).values()) {
int t = spotObject.getT();
// (rather than zero)
if (t == minT) {
String name = getFullName(Measurements.X_VELOCITY_PX, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.X_VELOCITY_CAL, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.Y_VELOCITY_PX, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.Y_VELOCITY_CAL, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.Z_VELOCITY_SLICES, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.Z_VELOCITY_CAL, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.INSTANTANEOUS_SPEED_PX, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.INSTANTANEOUS_SPEED_CAL, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, Double.NaN));
} else {
String name = getFullName(Measurements.X_VELOCITY_PX, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, xVelocity.get(t)));
name = getFullName(Measurements.X_VELOCITY_CAL, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, xVelocity.get(t) * distPerPxXY));
name = getFullName(Measurements.Y_VELOCITY_PX, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, yVelocity.get(t)));
name = getFullName(Measurements.Y_VELOCITY_CAL, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, yVelocity.get(t) * distPerPxXY));
name = getFullName(Measurements.Z_VELOCITY_SLICES, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, zVelocity.get(t) * distPerPxXY / distPerPxZ));
name = getFullName(Measurements.Z_VELOCITY_CAL, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, zVelocity.get(t) * distPerPxXY));
name = getFullName(Measurements.INSTANTANEOUS_SPEED_PX, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, speed.get(t)));
name = getFullName(Measurements.INSTANTANEOUS_SPEED_CAL, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, speed.get(t) * distPerPxXY));
}
}
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class MeasureTrackMotion method calculateRelativeTimepoint.
public static void calculateRelativeTimepoint(Obj trackObject, Track track, String inputSpotObjectsName, boolean averageSubtracted) {
if (track.size() == 0)
return;
int firstTimepoint = track.values().iterator().next().getF();
for (Obj spotObject : trackObject.getChildren(inputSpotObjectsName).values()) {
int currentTimepoint = spotObject.getT();
String name = getFullName(Measurements.RELATIVE_FRAME, averageSubtracted);
spotObject.addMeasurement(new Measurement(name, currentTimepoint - firstTimepoint));
}
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class MeasureTrackMotion method calculateVelocity.
public static void calculateVelocity(Obj trackObject, Track track, boolean averageSubtracted) {
if (track.size() <= 1) {
String name = getFullName(Measurements.MEAN_X_VELOCITY_PX, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.MEAN_X_VELOCITY_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.MEAN_Y_VELOCITY_PX, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.MEAN_Y_VELOCITY_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.MEAN_Z_VELOCITY_SLICES, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.MEAN_Z_VELOCITY_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.MEAN_INSTANTANEOUS_SPEED_PX, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
name = getFullName(Measurements.MEAN_INSTANTANEOUS_SPEED_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, Double.NaN));
} else {
// Calculating track motion
double distPerPxXY = trackObject.getDppXY();
double distPerPxZ = trackObject.getDppZ();
TreeMap<Integer, Double> xVelocity = track.getInstantaneousXVelocity();
TreeMap<Integer, Double> yVelocity = track.getInstantaneousYVelocity();
TreeMap<Integer, Double> zVelocity = track.getInstantaneousZVelocity();
TreeMap<Integer, Double> speed = track.getInstantaneousSpeed();
CumStat cumStatX = new CumStat();
CumStat cumStatY = new CumStat();
CumStat cumStatZ = new CumStat();
CumStat cumStatSpeed = new CumStat();
for (int frame : xVelocity.keySet()) {
// The first value is set to zero
if (frame == 0)
continue;
cumStatX.addMeasure(xVelocity.get(frame));
cumStatY.addMeasure(yVelocity.get(frame));
cumStatZ.addMeasure(zVelocity.get(frame));
cumStatSpeed.addMeasure(speed.get(frame));
}
String name = getFullName(Measurements.MEAN_X_VELOCITY_PX, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, cumStatX.getMean()));
name = getFullName(Measurements.MEAN_X_VELOCITY_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, cumStatX.getMean() * distPerPxXY));
name = getFullName(Measurements.MEAN_Y_VELOCITY_PX, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, cumStatY.getMean()));
name = getFullName(Measurements.MEAN_Y_VELOCITY_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, cumStatY.getMean() * distPerPxXY));
name = getFullName(Measurements.MEAN_Z_VELOCITY_SLICES, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, cumStatZ.getMean() * distPerPxXY / distPerPxZ));
name = getFullName(Measurements.MEAN_Z_VELOCITY_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, cumStatZ.getMean() * distPerPxXY));
name = getFullName(Measurements.MEAN_Z_VELOCITY_SLICES, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, cumStatZ.getMean() * distPerPxXY / distPerPxZ));
name = getFullName(Measurements.MEAN_Z_VELOCITY_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, cumStatZ.getMean() * distPerPxXY));
name = getFullName(Measurements.MEAN_INSTANTANEOUS_SPEED_PX, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, cumStatSpeed.getMean()));
name = getFullName(Measurements.MEAN_INSTANTANEOUS_SPEED_CAL, averageSubtracted);
trackObject.addMeasurement(new Measurement(name, cumStatSpeed.getMean() * distPerPxXY));
}
}
Aggregations