Search in sources :

Example 26 with Measurement

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()));
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) Obj(io.github.mianalysis.mia.object.Obj)

Example 27 with Measurement

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;
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) Obj(io.github.mianalysis.mia.object.Obj) Objs(io.github.mianalysis.mia.object.Objs) Image(io.github.mianalysis.mia.object.Image)

Example 28 with Measurement

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));
        }
    }
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) Obj(io.github.mianalysis.mia.object.Obj) Point(io.github.sjcross.common.object.Point) Timepoint(io.github.sjcross.common.object.tracks.Timepoint)

Example 29 with Measurement

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));
    }
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) Obj(io.github.mianalysis.mia.object.Obj) Point(io.github.sjcross.common.object.Point) Timepoint(io.github.sjcross.common.object.tracks.Timepoint)

Example 30 with Measurement

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));
    }
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) CumStat(io.github.sjcross.common.mathfunc.CumStat) Point(io.github.sjcross.common.object.Point) Timepoint(io.github.sjcross.common.object.tracks.Timepoint)

Aggregations

Measurement (io.github.mianalysis.mia.object.Measurement)105 Obj (io.github.mianalysis.mia.object.Obj)60 Objs (io.github.mianalysis.mia.object.Objs)35 Point (io.github.sjcross.common.object.Point)19 Image (io.github.mianalysis.mia.object.Image)17 ImagePlus (ij.ImagePlus)13 SpatCal (io.github.sjcross.common.object.volume.SpatCal)12 CumStat (io.github.sjcross.common.mathfunc.CumStat)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 EnumSource (org.junit.jupiter.params.provider.EnumSource)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Timepoint (io.github.sjcross.common.object.tracks.Timepoint)5 HashMap (java.util.HashMap)5 IntegerOverflowException (io.github.sjcross.common.exceptions.IntegerOverflowException)4 PointOutOfRangeException (io.github.sjcross.common.object.volume.PointOutOfRangeException)4 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)4 ImageStack (ij.ImageStack)3 Duplicator (ij.plugin.Duplicator)3 ProjectImage (io.github.mianalysis.mia.module.images.transform.ProjectImage)3 Interpreter (ij.macro.Interpreter)2