Search in sources :

Example 21 with Measurement

use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.

the class RelateManyToOne method calculateFractionalDistance.

public static void calculateFractionalDistance(Obj childObject, Obj parentObject, double minDist) {
    // Calculating the furthest distance to the edge
    if (parentObject.getMeasurement("MAX_DIST") == null) {
        // Creating an image for the parent object
        Image parentImage = parentObject.getAsImage("Parent", false);
        Image distImage = DistanceMap.process(parentImage, "Distance", true, DistanceMap.WeightModes.WEIGHTS_3_4_5_7, true, false);
        Image projectedImage = ProjectImage.projectImageInZ(distImage, "Projected", ProjectImage.ProjectionModes.MAX);
        double maxDist = projectedImage.getImagePlus().getStatistics().max;
        parentObject.addMeasurement(new Measurement("MAX_DIST", maxDist));
    }
    // Adding measurement
    double maxDist = parentObject.getMeasurement("MAX_DIST").getValue();
    double frac = Math.abs(minDist / maxDist);
    String measurementName = getFullName(Measurements.DIST_CENT_SURF_FRAC, parentObject.getName());
    childObject.addMeasurement(new Measurement(measurementName, frac));
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) Image(io.github.mianalysis.mia.object.Image) ProjectImage(io.github.mianalysis.mia.module.images.transform.ProjectImage)

Example 22 with Measurement

use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.

the class RelateManyToOne method applyLinkMeasurements.

static void applyLinkMeasurements(Objs parentObjects, Objs childObjects) {
    String parentMeasurementName = getFullName(Measurements.WAS_LINKED, childObjects.getName());
    String childMeasurementName = getFullName(Measurements.WAS_LINKED, parentObjects.getName());
    for (Obj parentObject : parentObjects.values()) {
        if (parentObject.getChildren(childObjects.getName()).size() == 0) {
            parentObject.addMeasurement(new Measurement(parentMeasurementName, 0));
        } else {
            parentObject.addMeasurement(new Measurement(parentMeasurementName, 1));
        }
    }
    for (Obj childObject : childObjects.values()) {
        if (childObject.getParent(parentObjects.getName()) == null) {
            childObject.addMeasurement(new Measurement(childMeasurementName, 0));
        } else {
            childObject.addMeasurement(new Measurement(childMeasurementName, 1));
        }
    }
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) Obj(io.github.mianalysis.mia.object.Obj)

Example 23 with Measurement

use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.

the class RelateManyToOne method linkByCentroidProximity.

public static void linkByCentroidProximity(Objs parentObjects, Objs childObjects, boolean linkInSameFrame, double linkingDistance, int nThreads) {
    String moduleName = RelateObjects.class.getSimpleName();
    String measurementNamePx = getFullName(Measurements.DIST_CENTROID_PX, parentObjects.getName());
    String measurementNameCal = getFullName(Measurements.DIST_CENTROID_CAL, parentObjects.getName());
    AtomicInteger count = new AtomicInteger(1);
    int numberOfChildren = childObjects.size();
    // Ensuring all parent objects have a calculated centroid
    for (Obj parent : parentObjects.values()) parent.getMeanCentroid();
    ThreadPoolExecutor pool = new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
    for (Obj childObject : childObjects.values()) {
        Runnable task = () -> {
            double minDist = Double.MAX_VALUE;
            Obj minLink = null;
            double dpp = childObject.getDppXY();
            for (Obj parentObject : parentObjects.values()) {
                if (linkInSameFrame & parentObject.getT() != childObject.getT())
                    continue;
                double dist = childObject.getCentroidSeparation(parentObject, true);
                if (dist < minDist && dist <= linkingDistance) {
                    minDist = dist;
                    minLink = parentObject;
                }
            }
            // Adding measurements to the input object
            if (minLink != null) {
                childObject.addParent(minLink);
                minLink.addChild(childObject);
                childObject.addMeasurement(new Measurement(measurementNamePx, minDist));
                childObject.addMeasurement(new Measurement(measurementNameCal, minDist * dpp));
            } else {
                childObject.addMeasurement(new Measurement(measurementNamePx, Double.NaN));
                childObject.addMeasurement(new Measurement(measurementNameCal, Double.NaN));
            }
            writeProgressStatus(count.getAndIncrement(), numberOfChildren, "objects", moduleName);
        };
        pool.submit(task);
    }
    pool.shutdown();
    try {
        // i.e. never terminate early
        pool.awaitTermination(Integer.MAX_VALUE, TimeUnit.DAYS);
    } catch (InterruptedException e) {
    // Do nothing as the user has selected this
    }
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Obj(io.github.mianalysis.mia.object.Obj) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Point(io.github.sjcross.common.object.Point)

Example 24 with Measurement

use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.

the class RelateManyToOne method spatialOverlap.

public void spatialOverlap(Objs parentObjects, Objs childObjects, double minOverlap, boolean centroidOverlap, boolean linkInSameFrame) {
    long nCombined = parentObjects.size() * childObjects.size();
    long count = 0;
    String overlapMeasurementName = getFullName(Measurements.OVERLAP_PC, parentObjects.getName());
    // If there are no objects to link, just set all children to no link
    if (nCombined == 0)
        return;
    // Runs through each child object against each parent object
    for (Obj parentObject : parentObjects.values()) {
        for (Obj childObject : childObjects.values()) {
            // Testing if the two objects are in the same frame (if this matters)
            if (linkInSameFrame && parentObject.getT() != childObject.getT())
                continue;
            // If requiring the child centroid is overlapped with the parent object
            if (centroidOverlap) {
                int xCent = (int) Math.round(childObject.getXMean(true));
                int yCent = (int) Math.round(childObject.getYMean(true));
                // Relates to image location
                int zCent = (int) Math.round(childObject.getZMean(true, false));
                Point<Integer> centroid = new Point<>(xCent, yCent, zCent);
                // If the centroid doesn't overlap, skip this link
                if (!parentObject.contains(centroid))
                    continue;
            }
            // Calculates the percentage overlap
            double nTotal = (double) childObject.size();
            double nOverlap = (double) parentObject.getOverlap(childObject);
            double overlap = (nOverlap / nTotal) * 100;
            // Testing the minimum overlap requirement
            if (overlap == 0 || overlap <= minOverlap)
                continue;
            // If the tests are successful, addRef the link. If the child has already been
            // linked, but with a smaller
            // overlap, remove that link.
            Obj oldParent = childObject.getParent(parentObject.getName());
            if (oldParent != null) {
                if (childObject.getMeasurement(overlapMeasurementName).getValue() < overlap) {
                    oldParent.removeChild(childObject);
                } else {
                    // If the previous link had a better overlap, skip the assignment
                    continue;
                }
            }
            // Creating the link
            parentObject.addChild(childObject);
            childObject.addParent(parentObject);
            // Adding the overlap as a measurement
            Measurement measurement = new Measurement(getFullName(Measurements.OVERLAP_PC, parentObject.getName()));
            measurement.setValue(overlap);
            childObject.addMeasurement(measurement);
        }
        writeStatus("Compared " + Math.floorDiv(100 * childObjects.size() * ++count, nCombined) + "% of pairs");
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Measurement(io.github.mianalysis.mia.object.Measurement) Obj(io.github.mianalysis.mia.object.Obj) Point(io.github.sjcross.common.object.Point) Point(io.github.sjcross.common.object.Point)

Example 25 with Measurement

use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.

the class TrackObjects method getMeasurementCost.

public static double getMeasurementCost(Obj prevObj, Obj currObj, String measurementName) {
    Measurement currMeasurement = currObj.getMeasurement(measurementName);
    Measurement prevMeasurement = prevObj.getMeasurement(measurementName);
    if (currMeasurement == null || prevMeasurement == null)
        return Double.NaN;
    double currMeasurementValue = currMeasurement.getValue();
    double prevMeasurementValue = prevMeasurement.getValue();
    return Math.abs(prevMeasurementValue - currMeasurementValue);
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement)

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