use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class MeasureObjectCurvature method measureCurvature.
public static void measureCurvature(Obj inputObject, TreeMap<Double, Double> curvature, boolean absoluteCurvature, boolean signedCurvature) {
double dppXY = inputObject.getDppXY();
CumStat cumStatSigned = new CumStat();
CumStat cumStatAbsolute = new CumStat();
for (double value : curvature.values()) {
if (absoluteCurvature)
cumStatAbsolute.addMeasure(Math.abs(value));
if (signedCurvature)
cumStatSigned.addMeasure(value);
}
// Adding measurements
if (absoluteCurvature) {
inputObject.addMeasurement(new Measurement(Measurements.MEAN_ABSOLUTE_CURVATURE_PX, cumStatAbsolute.getMean()));
inputObject.addMeasurement(new Measurement(Measurements.MIN_ABSOLUTE_CURVATURE_PX, cumStatAbsolute.getMin()));
inputObject.addMeasurement(new Measurement(Measurements.MAX_ABSOLUTE_CURVATURE_PX, cumStatAbsolute.getMax()));
inputObject.addMeasurement(new Measurement(Measurements.STD_ABSOLUTE_CURVATURE_PX, cumStatAbsolute.getStd()));
inputObject.addMeasurement(new Measurement(Measurements.MEAN_ABSOLUTE_CURVATURE_CAL, cumStatAbsolute.getMean() / dppXY));
inputObject.addMeasurement(new Measurement(Measurements.MIN_ABSOLUTE_CURVATURE_CAL, cumStatAbsolute.getMin() / dppXY));
inputObject.addMeasurement(new Measurement(Measurements.MAX_ABSOLUTE_CURVATURE_CAL, cumStatAbsolute.getMax() / dppXY));
inputObject.addMeasurement(new Measurement(Measurements.STD_ABSOLUTE_CURVATURE_CAL, cumStatAbsolute.getStd() / dppXY));
}
if (signedCurvature) {
inputObject.addMeasurement(new Measurement(Measurements.MEAN_SIGNED_CURVATURE_PX, cumStatSigned.getMean()));
inputObject.addMeasurement(new Measurement(Measurements.MIN_SIGNED_CURVATURE_PX, cumStatSigned.getMin()));
inputObject.addMeasurement(new Measurement(Measurements.MAX_SIGNED_CURVATURE_PX, cumStatSigned.getMax()));
inputObject.addMeasurement(new Measurement(Measurements.STD_SIGNED_CURVATURE_PX, cumStatSigned.getStd()));
inputObject.addMeasurement(new Measurement(Measurements.MEAN_SIGNED_CURVATURE_CAL, cumStatSigned.getMean() / dppXY));
inputObject.addMeasurement(new Measurement(Measurements.MIN_SIGNED_CURVATURE_CAL, cumStatSigned.getMin() / dppXY));
inputObject.addMeasurement(new Measurement(Measurements.MAX_SIGNED_CURVATURE_CAL, cumStatSigned.getMax() / dppXY));
inputObject.addMeasurement(new Measurement(Measurements.STD_SIGNED_CURVATURE_CAL, cumStatSigned.getStd() / dppXY));
}
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class MeasureObjectColocalisation method setObjectMeasurements.
public void setObjectMeasurements(Obj obj, HashMap<String, Double> measurements, String imageName1, String imageName2) {
for (String measurementName : measurements.keySet()) {
String fullName = getFullName(imageName1, imageName2, measurementName);
obj.addMeasurement(new Measurement(fullName, measurements.get(measurementName)));
}
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class MeasureObjectTexture method processObject.
public static void processObject(Obj object, Image image, TextureCalculator textureCalculator, double[] offs, boolean calibratedOffset) {
ImagePlus ipl = image.getImagePlus();
// If the input stack is a single timepoint and channel, there's no need to
// create a new ImageStack
ImageStack timeStack = null;
if (ipl.getNChannels() == 1 && ipl.getNFrames() == 1) {
timeStack = ipl.getStack();
} else {
int t = object.getT() + 1;
int nSlices = ipl.getNSlices();
timeStack = SubHyperstackMaker.makeSubhyperstack(ipl, "1-1", "1-" + nSlices, t + "-" + t).getStack();
}
textureCalculator.calculate(timeStack, object, (int) offs[0], (int) offs[1], (int) offs[2]);
// Acquiring measurements
String name = getFullName(image.getName(), Measurements.ASM, offs, calibratedOffset);
object.addMeasurement(new Measurement(name, textureCalculator.getASM()));
name = getFullName(image.getName(), Measurements.CONTRAST, offs, calibratedOffset);
object.addMeasurement(new Measurement(name, textureCalculator.getContrast()));
name = getFullName(image.getName(), Measurements.CORRELATION, offs, calibratedOffset);
object.addMeasurement(new Measurement(name, textureCalculator.getCorrelation()));
name = getFullName(image.getName(), Measurements.ENTROPY, offs, calibratedOffset);
object.addMeasurement(new Measurement(name, textureCalculator.getEntropy()));
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class FilterByChildren method process.
@Override
protected Status process(Workspace workspace) {
// Getting input objects
String inputObjectsName = parameters.getValue(INPUT_OBJECTS);
Objs inputObjects = workspace.getObjects().get(inputObjectsName);
// Getting parameters
String filterMode = parameters.getValue(FILTER_MODE);
String outputObjectsName = parameters.getValue(OUTPUT_FILTERED_OBJECTS);
String filterMethod = parameters.getValue(FILTER_METHOD);
String childObjectsName = parameters.getValue(CHILD_OBJECTS);
boolean storeSummary = parameters.getValue(STORE_SUMMARY_RESULTS);
boolean storeIndividual = parameters.getValue(STORE_INDIVIDUAL_RESULTS);
boolean moveObjects = filterMode.equals(FilterModes.MOVE_FILTERED);
boolean remove = !filterMode.equals(FilterModes.DO_NOTHING);
Objs outputObjects = moveObjects ? new Objs(outputObjectsName, inputObjects) : null;
int count = 0;
Iterator<Obj> iterator = inputObjects.values().iterator();
while (iterator.hasNext()) {
Obj inputObject = iterator.next();
Objs childObjects = inputObject.getChildren(childObjectsName);
// Removing the object if it has no children
if (childObjects == null) {
count++;
if (remove)
processRemoval(inputObject, outputObjects, iterator);
continue;
}
double value = childObjects.size();
double refValue = getReferenceValue(workspace, inputObject);
boolean conditionMet = testFilter(value, refValue, filterMethod);
// Adding measurements
if (storeIndividual) {
String measurementName = getIndividualMeasurementName(childObjectsName);
inputObject.addMeasurement(new Measurement(measurementName, conditionMet ? 1 : 0));
}
// Removing the object if it has too few children
if (conditionMet) {
count++;
if (remove)
processRemoval(inputObject, outputObjects, iterator);
}
}
// If moving objects, addRef them to the workspace
if (moveObjects)
workspace.addObjects(outputObjects);
// If storing the result, create a new metadata item for it
if (storeSummary) {
String metadataName = getSummaryMeasurementName(childObjectsName);
workspace.getMetadata().put(metadataName, count);
}
// Showing objects
if (showOutput)
inputObjects.convertToImageRandomColours().showImage();
return Status.PASS;
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class FilterByMeasurementExtremes method process.
@Override
protected Status process(Workspace workspace) {
// Getting input objects
String inputObjectsName = parameters.getValue(INPUT_OBJECTS);
Objs inputObjects = workspace.getObjects().get(inputObjectsName);
// Getting parameters
String filterMode = parameters.getValue(FILTER_MODE);
String outputObjectsName = parameters.getValue(OUTPUT_FILTERED_OBJECTS);
String filterMethod = parameters.getValue(FILTER_METHOD);
boolean perTimepoint = parameters.getValue(PER_TIMEPOINT);
String measName = parameters.getValue(MEASUREMENT);
boolean moveObjects = filterMode.equals(FilterModes.MOVE_FILTERED);
boolean remove = !filterMode.equals(FilterModes.DO_NOTHING);
Objs outputObjects = moveObjects ? new Objs(outputObjectsName, inputObjects) : null;
// Getting reference limits
HashMap<Integer, double[]> minMax = getMeasurementExtremes(inputObjects, measName, perTimepoint);
Iterator<Obj> iterator = inputObjects.values().iterator();
while (iterator.hasNext()) {
Obj inputObject = iterator.next();
Measurement measurement = inputObject.getMeasurement(measName);
if (measurement == null)
continue;
// Getting the values to filter on
double value = measurement.getValue();
int t = perTimepoint ? inputObject.getT() : 0;
double[] currMinMax = minMax.get(t);
boolean conditionMet = testFilter(value, currMinMax, filterMethod);
// Removing the object if it failed the test
if (conditionMet && remove)
processRemoval(inputObject, outputObjects, iterator);
}
// If moving objects, addRef them to the workspace
if (moveObjects)
workspace.addObjects(outputObjects);
// Showing objects
if (showOutput)
inputObjects.convertToImageRandomColours().showImage();
return Status.PASS;
}
Aggregations