Search in sources :

Example 11 with Measurement

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);
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement)

Example 12 with Measurement

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;
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) Interpreter(ij.macro.Interpreter) ParameterGroup(io.github.mianalysis.mia.object.parameters.ParameterGroup) Image(io.github.mianalysis.mia.object.Image) ImagePlus(ij.ImagePlus)

Example 13 with Measurement

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));
        }
    }
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) Obj(io.github.mianalysis.mia.object.Obj)

Example 14 with Measurement

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);
    }
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) Obj(io.github.mianalysis.mia.object.Obj) Point(io.github.sjcross.common.object.Point)

Example 15 with Measurement

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);
    }
}
Also used : Measurement(io.github.mianalysis.mia.object.Measurement) Obj(io.github.mianalysis.mia.object.Obj) Point(io.github.sjcross.common.object.Point)

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