use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class AbstractMacroRunner method interceptMeasurement.
public static Measurement interceptMeasurement(ResultsTable table, String heading) {
if (table == null || table.getColumn(0) == null)
return new Measurement(getFullName(heading), Double.NaN);
int nRows = table.getColumn(0).length;
double value = table.getValue(heading, nRows - 1);
return new Measurement(getFullName(heading), value);
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class RunMacro method process.
@Override
public Status process(Workspace workspace) {
// Getting input image
boolean provideInputImage = parameters.getValue(PROVIDE_INPUT_IMAGE);
String inputImageName = parameters.getValue(INPUT_IMAGE);
String macroMode = parameters.getValue(MACRO_MODE);
String macroText = parameters.getValue(MACRO_TEXT);
String macroFile = parameters.getValue(MACRO_FILE);
boolean interceptOutputImage = parameters.getValue(INTERCEPT_OUTPUT_IMAGE);
boolean applyToInput = parameters.getValue(APPLY_TO_INPUT);
String outputImageName = parameters.getValue(OUTPUT_IMAGE);
// Getting a list of measurement headings
ParameterGroup measurementGroup = parameters.getParameter(ADD_INTERCEPTED_VARIABLE);
LinkedHashSet<String> expectedMeasurements = expectedMeasurements(measurementGroup, VARIABLE);
// Setting the MacroHandler to the current workspace
MacroHandler.setWorkspace(workspace);
MacroHandler.setModules(modules);
// Get current image
Image inputImage = provideInputImage ? workspace.getImage(inputImageName) : null;
ImagePlus inputImagePlus = (inputImage != null) ? inputImage.getImagePlus().duplicate() : null;
// If the macro is stored as a file, load this to the macroText string
if (macroMode.equals(MacroModes.MACRO_FILE)) {
macroText = IJ.openAsString(macroFile);
macroText = GlobalVariables.convertString(macroText, modules);
macroText = TextType.applyCalculation(macroText);
}
// Appending variables to the front of the macro
ParameterGroup variableGroup = parameters.getParameter(ADD_VARIABLE);
String finalMacroText = addVariables(macroText, variableGroup);
// If providing the input image direct from the workspace, hide all open windows
// while the macro runs
ArrayList<ImagePlus> openImages = null;
if (provideInputImage)
openImages = hideImages();
// Running the macro
Interpreter interpreter = new Interpreter();
interpreter.setIgnoreErrors(true);
try {
inputImagePlus = interpreter.runBatchMacro(finalMacroText, inputImagePlus);
if (interpreter.getErrorMessage() != null)
throw new RuntimeException();
} catch (RuntimeException e) {
IJ.runMacro("setBatchMode(false)");
if (provideInputImage)
for (ImagePlus openImage : openImages) openImage.show();
MIA.log.writeError("Macro failed with error \"" + interpreter.getErrorMessage() + "\". Skipping file.");
return Status.FAIL;
}
// windows
if (provideInputImage)
for (ImagePlus openImage : openImages) openImage.show();
if (interceptOutputImage && inputImagePlus != null) {
if (applyToInput && inputImage != null) {
inputImage.setImagePlus(inputImagePlus);
if (showOutput)
inputImage.showImage();
} else {
Image outputImage = new Image(outputImageName, inputImagePlus);
workspace.addImage(outputImage);
if (showOutput)
outputImage.showImage();
}
}
// Intercepting measurements
if (provideInputImage) {
for (String expectedMeasurement : expectedMeasurements) {
double value = interpreter.getVariable(expectedMeasurement);
Measurement measurement = new Measurement(getFullName(expectedMeasurement), value);
inputImage.addMeasurement(measurement);
}
}
return Status.PASS;
}
use of io.github.mianalysis.mia.object.Measurement in project mia by mianalysis.
the class TrackEditor method addSingleTimepointTracks.
static void addSingleTimepointTracks(Set<Integer> trackIDs, Objs spotObjects, Objs trackObjects, String inputTrackObjectsName) {
// Determining the maximum current track ID
int maxID = 0;
for (int trackID : trackIDs) maxID = Math.max(maxID, trackID);
// Single timepoint "tracks" aren't assigned track IDs yet, so doing that now
for (Obj obj : spotObjects.values()) {
if (obj.getParent(inputTrackObjectsName) == null) {
Obj trackObject = trackObjects.createAndAddNewObject(VolumeType.POINTLIST, ++maxID + 1);
obj.addParent(trackObject);
trackObject.addChild(obj);
obj.addMeasurement(new Measurement(Measurements.TRACK_NEXT_ID, Double.NaN));
obj.addMeasurement(new Measurement(Measurements.TRACK_PREV_ID, Double.NaN));
}
}
}
use of io.github.mianalysis.mia.object.Measurement 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.mianalysis.mia.object.Measurement 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);
}
}
Aggregations