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 };
}
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;
}
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);
}
}
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);
}
}
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);
}
Aggregations