Search in sources :

Example 1 with Point

use of io.github.sjcross.common.object.Point in project mia by mianalysis.

the class AddLabels method getInsideObjectLocation.

public static double[] getInsideObjectLocation(Obj obj) {
    // Binarise object and calculate its distance map
    Image binaryImage = obj.getAsImage("Binary", false);
    BinaryOperations2D.process(binaryImage, BinaryOperations2D.OperationModes.ERODE, 1, 1, true);
    ImagePlus distanceIpl = DistanceMap.process(binaryImage, "Distance", true, DistanceMap.WeightModes.WEIGHTS_3_4_5_7, true, false).getImagePlus();
    ImageStack distanceIst = distanceIpl.getStack();
    // Get location of largest value
    Point<Integer> bestPoint = null;
    double distance = Double.MIN_VALUE;
    for (Point<Integer> point : obj.getCoordinateSet()) {
        int idx = distanceIpl.getStackIndex(1, point.getZ() + 1, obj.getT() + 1);
        float currDistance = distanceIst.getProcessor(idx).getf(point.getX(), point.getY());
        if (currDistance > distance) {
            distance = currDistance;
            bestPoint = point;
        }
    }
    // Returning this point
    return new double[] { bestPoint.getX(), bestPoint.getY(), bestPoint.getZ() + 1 };
}
Also used : ImageStack(ij.ImageStack) Image(io.github.mianalysis.mia.object.Image) ImagePlus(ij.ImagePlus) Point(io.github.sjcross.common.object.Point)

Example 2 with Point

use of io.github.sjcross.common.object.Point in project mia by mianalysis.

the class MaskObjects method maskObject.

public static <T extends RealType<T> & NativeType<T>> Obj maskObject(Obj inputObject, Image maskImage) {
    Objs tempObjects = new Objs("Mask objects", inputObject.getObjectCollection());
    // Creating the mask object
    Obj maskObject = tempObjects.createAndAddNewObject(inputObject.getVolumeType(), inputObject.getID());
    maskObject.setT(inputObject.getT());
    ImgPlus<T> maskImg = maskImage.getImgPlus();
    RandomAccess<T> randomAccess = maskImg.randomAccess();
    int xAx = maskImg.dimensionIndex(Axes.X);
    int yAx = maskImg.dimensionIndex(Axes.Y);
    int cAx = maskImg.dimensionIndex(Axes.CHANNEL);
    int zAx = maskImg.dimensionIndex(Axes.Z);
    int tAx = maskImg.dimensionIndex(Axes.TIME);
    // intensity
    for (Point<Integer> point : inputObject.getCoordinateSet()) {
        long[] location = new long[maskImg.numDimensions()];
        if (xAx != -1)
            location[xAx] = point.getX();
        if (yAx != -1)
            location[yAx] = point.getY();
        if (cAx != -1)
            location[cAx] = 0;
        if (zAx != -1)
            location[zAx] = point.getZ();
        if (tAx != -1)
            location[tAx] = inputObject.getT();
        randomAccess.setPosition(location);
        int value = ((UnsignedByteType) randomAccess.get()).get();
        if (value != 0) {
            try {
                maskObject.add(point);
            } catch (PointOutOfRangeException e) {
            }
        }
    }
    return maskObject;
}
Also used : PointOutOfRangeException(io.github.sjcross.common.object.volume.PointOutOfRangeException) Obj(io.github.mianalysis.mia.object.Obj) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType) Objs(io.github.mianalysis.mia.object.Objs) Point(io.github.sjcross.common.object.Point)

Example 3 with Point

use of io.github.sjcross.common.object.Point in project mia by mianalysis.

the class CreateMeasurementMap method processParentMeasurements.

public static void processParentMeasurements(CumStat[] cumStats, Indexer indexer, Objs objects, String parentObjectsName, String measurementName, @Nullable String message) {
    // Adding objects
    int count = 0;
    int nTotal = objects.size();
    for (Obj object : objects.values()) {
        // Getting parent object
        Obj parentObject = object.getParent(parentObjectsName);
        if (parentObject == null)
            continue;
        // Getting measurement value. Skip if null or NaN.
        Measurement measurement = parentObject.getMeasurement(measurementName);
        if (measurement == null)
            continue;
        double measurementValue = measurement.getValue();
        if (Double.isNaN(measurementValue))
            continue;
        // Getting all object points
        for (Point<Integer> point : object.getCoordinateSet()) {
            // Getting index for this point
            int z = indexer.getDim()[2] == 1 ? 0 : point.getZ();
            int t = indexer.getDim()[3] == 1 ? 0 : object.getT();
            int idx = indexer.getIndex(new int[] { point.getX(), point.getY(), z, t });
            // Adding measurement
            cumStats[idx].addMeasure(measurementValue);
        }
        if (message != null)
            writeProgressStatus(++count, nTotal, "objects", message);
    }
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) Obj(io.github.mianalysis.mia.object.Obj) Point(io.github.sjcross.common.object.Point)

Example 4 with Point

use of io.github.sjcross.common.object.Point in project mia by mianalysis.

the class CreateMeasurementMap method processObjectMeasurement.

public static void processObjectMeasurement(CumStat[] cumStats, Indexer indexer, Objs objects, String measurementName, @Nullable String message) {
    // Adding objects
    int count = 0;
    int nTotal = objects.size();
    for (Obj object : objects.values()) {
        // Getting measurement value. Skip if null or NaN.
        Measurement measurement = object.getMeasurement(measurementName);
        if (measurement == null)
            continue;
        double measurementValue = measurement.getValue();
        if (Double.isNaN(measurementValue))
            continue;
        // Getting all object points
        for (Point<Integer> point : object.getCoordinateSet()) {
            // Getting index for this point
            int z = indexer.getDim()[2] == 1 ? 0 : point.getZ();
            int t = indexer.getDim()[3] == 1 ? 0 : object.getT();
            int idx = indexer.getIndex(new int[] { point.getX(), point.getY(), z, t });
            // Adding measurement
            cumStats[idx].addMeasure(measurementValue);
        }
        if (message != null)
            writeProgressStatus(++count, nTotal, "objects", message);
    }
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) Obj(io.github.mianalysis.mia.object.Obj) Point(io.github.sjcross.common.object.Point)

Example 5 with Point

use of io.github.sjcross.common.object.Point in project mia by mianalysis.

the class WidthMeasurementResult method getObjectReference.

public static Point<Double> getObjectReference(final Obj obj, final String xMeasName, final String yMeasName, final String zMeasName) {
    final SpatCal spatCal = obj.getSpatialCalibration();
    final double xMeas = obj.getMeasurement(xMeasName).getValue();
    final double yMeas = obj.getMeasurement(yMeasName).getValue();
    final double zMeas = obj.getMeasurement(zMeasName).getValue() * (spatCal.dppZ / spatCal.dppXY);
    return new Point<Double>(xMeas, yMeas, zMeas);
}
Also used : Point(io.github.sjcross.common.object.Point) SpatCal(io.github.sjcross.common.object.volume.SpatCal)

Aggregations

Point (io.github.sjcross.common.object.Point)137 Obj (io.github.mianalysis.mia.object.Obj)112 Objs (io.github.mianalysis.mia.object.Objs)100 SpatCal (io.github.sjcross.common.object.volume.SpatCal)89 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)88 EnumSource (org.junit.jupiter.params.provider.EnumSource)88 ImagePlus (ij.ImagePlus)14 PointOutOfRangeException (io.github.sjcross.common.object.volume.PointOutOfRangeException)11 Measurement (io.github.mianalysis.mia.object.Measurement)9 Image (io.github.mianalysis.mia.object.Image)6 ImageProcessor (ij.process.ImageProcessor)3 Volume (io.github.sjcross.common.object.volume.Volume)3 HashMap (java.util.HashMap)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ImageStack (ij.ImageStack)2 Timepoint (io.github.sjcross.common.object.tracks.Timepoint)2 CoordinateSet (io.github.sjcross.common.object.volume.CoordinateSet)2 VolumeType (io.github.sjcross.common.object.volume.VolumeType)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2