Does anyone help me with the use of setResults function in a macro?

measure
imagej
macro
call4help

#1

Hi,

I want to measure in each image of an animation the area of diferent things with the wand tool, and I want to put the results in diferent columns in the results window. Does anyone help me with the use of setResults function in my macro?

this is my macro:

run("Set Measurements...", "area redirect=None decimal=3");

for(i = 1; i <= nSlices; i++){
setSlice(i);
//setTool("wand");
doWand(92, 242, 30.0, "Legacy");
run("Measure");
}

for(i = 1; i <= nSlices; i++){
setSlice(i);
//setTool("wand");
doWand(143, 196, 30.0, "Legacy");
run("Measure");
}

Thanks a lot.


#2

Dear @juandemedellin,

you can’t use run("Measure") in your case because that will write into the results table that you are trying to create. You can use List.setMeasurements to measure the currently active selection and List.getValue("Area") to get the area of that selection. You can replace "Area" with any column header from the results table that would be generated by the call run("Measure"):

run("Set Measurements...", "area redirect=None decimal=3");

for(i = 1; i <= nSlices; i++){
setSlice(i);
//setTool("wand");
doWand(92, 242, 30.0, "Legacy");
List.setMeasurements;
area1 = List.getValue("Area");
setResult("Area 1", i, area1);
}

for(i = 1; i <= nSlices; i++){
setSlice(i);
//setTool("wand");
doWand(143, 196, 30.0, "Legacy");
List.setMeasurements;
area2 = List.getValue("Area");
setResult("Area 2", i, area2);
}

Best,
Stefan


#3

Dear Stefan Helfrich

When I run the macro I get this error:


#4

Dear Stefan Helfrich,

my friends and I resolved it in this way:

Thanks a lot.


#5

I have the same same problem, as did this person:https://forum.image.sc/t/imagej-setresult/6297. I am using Fiji (ImageJ Version 2.0.0-rc-68/1.52e. Build bad6864e55).

This simple macro illustrates my problem:

run(“Clear Results”);
a=newArray(1,2,3,4,5);
for (i=0;i<lengthOf(a);i++); {
setResult(“Data”,i,a[i]);
}
updateResults();

The Results window is simple, just having 1 row with the row number, Area, X and Y columns.
It returns the following error message:

Index(5) out of 0-4 range in line 5:
setResult (“Data”,i,a[i]);

I have large datasets, so the workaround of the type described by juandemedellin is not suitable.

Any help welcome.


#6

Good day!

Try this:

run("Clear Results");
a=newArray(1,2,3,4,5);
for (i=0;i<a.length;i++) {
   setResult("Data",i,a[i]);
}
updateResults();

Two syntax errors!

Regards

Herbie


#7

The dreaded semi-colon …

Thanks, Herbie!


#8

Not only and to err is human. Poor little semicolon.

Herbie