Macro MorpholibJ Intensity Measurements 2D/3D

Hello out there,
I am trying to polish a macro in which I want to embed the MorpholibJ function “Intensity Measurements 2D/3D” into a function in order to call it with different inputs and labels.

//measure in MorpholibJ and save Results
outputDirectory = "/Users/imle/Desktop/Microscopy/Airy Scan/200303 PBMC Coll647/Day4/Processed/"
name = getTitle();
MeasureMorphoLib("Collagen", "Phalloidin-thresholded-fillHoles_dilated_ref-lbl");

function MeasureMorphoLib (inputImage, labelsImage) {
	run("Intensity Measurements 2D/3D", "input='inputImage' labels='labelsImage' mean stddev max min median numberofvoxels volume");
	saveAs("Results", outputDirectory + name + labelsImage + ".csv");

The macro runs and does not give an error. But…
The Result is not the same as when I call the plugin from the GUI, but it always gives the result of the last plugin run.
For example:
I have 2 LabelImages (they were done with Ext.CLIJ2_connectedComponentsLabeling)

labelsImage 1 contains only 1 label
labelsImage 2 contains 2 labels

Manually I call the “Intensity Measurements 2D/3D” plugin using labelsimage1. The result is correct with only 1 line in the Results window.

Afterwards I call the macro with labelsImage2. The result window which is newly computed only has the 1 line from the previous computing.

I am quite new to the Function business. Does anyone have an idea for me?
I am puzzled.

So long, and thanks already now for any brain power that you put into this.

All the best,


So I think it might have to do with what variables you are passing to the function call and which ones you aren’t… This is what I would do to test things:

  1. throw some print() statements before, within, and after the function call - to be sure your variables are as they should be…

  2. it might be that you have to pass more variables to the function… since you are using them - the function might need to be:

function MeasureMorphoLib (inputImage, labelsImage, name, outputDirectory) {
  1. also your concatenation within the function call is incorrect when using the variables, inputImage and labelsImage… it should be:
	run("Intensity Measurements 2D/3D", "input=" + inputImage +  "labels=" + labelsImage + " mean stddev max min median numberofvoxels volume");
  1. and definitely test that the path you are writing out in your saveAs() is correct - might be that you need to include some File.separator 's between variables

Hope this helps.

Thanks @etadobson.
The +inputImage+ did it.
I really appreciate it.


1 Like