Unable to retrieve columns from Results Table in Java

imagej1
imagej
roi
java
results-table

#1

To draw a convex hull, I need the starting co-ordinates for each ROI in the ROI Manager. For a particular image, I perform ‘Analyze Particles’ and I get the corresponding features : ‘Area’, ‘Perimeter’, ‘XStart’, ‘YStart’ printed in the console window of Eclipse. However, when I try to retrieve the values from ‘XStart’ and ‘YStart’ columns, it displays an error stating: "XStart" column not found. Here’s my code snippet:

Versatile_Wand obj = new Versatile_Wand();
ResultsTable RT1 = new ResultsTable();
IJ.run("Set Measurements...", "area perimeter redirect=None decimal=3");
IJ.run(Gchannel, "Analyze Particles...", "size=5-700000 circularity=0.10-1.00 show=Outlines display clear record include summarize add in_situ");
RoiManager rm1 = RoiManager.getInstance();
rm1.multiMeasure(CS);
Analyzer.setResultsTable(RT1);
rm1.select(5);
obj.doWand(CS, (int)(RT1.getValue("XStart", 5)),(int)(RT1.getValue("YStart", 5)));

The error: ij.measure.ResultsTable.getValue(ResultsTable.java:376)

Results


#2

Dear @kbimagej,

from http://javadoc.scijava.org/ImageJ1/ij/measure/ResultsTable.html

getResultsTable()
Returns the ResultsTable used by the Measure command.

Instead of creating a ResultsTable manually, could you try to use ResultsTable RT1 = ResultsTable.getResultsTable() after executing Analyze Particles?

Best,
Stefan


#3

Shoud rm1.multiMeasure(CS) operation be performed before or after getResultsTable()?


#4

With the parameter string that you are using for Analyze Particles, you will already create a ResultsTable (the display keyword) with entries for all the particles. Hence, you don’t necessarily need multiMeasure (if I interpreted your intentions correctly). That said, if multiMeasure does not clear the results table, it shouldn’t really matter since the ResultsTable instance should be the same. To be on the safe side, have ResultsTable.getResultsTable() after multiMeasure().


#5

It didn’t work. Gives the same error. And now, it doesn’t even print the XStart and YStart on the console window. Here’s my current code snippet:

Versatile_Wand_Tool obj = new Versatile_Wand_Tool();
RoiManager rm1 = RoiManager.getInstance();
if (rm1==null) rm1 = new RoiManager();
IJ.run("Set Measurements...", "area perimeter redirect=None decimal=3");
IJ.run(Gchannel, "Analyze Particles...", "size=5-700000 circularity=0.10-1.00 show=Outlines display clear record include summarize add in_situ");
rm1.multiMeasure(CS);
ResultsTable RT1 = ResultsTable.getResultsTable();
System.out.println(RT1.getValue("XStart", 1)); // Just to check if there is a column and its corresponding value

#6

Hmm. Here is a Groovy script that you can run from within the Script Editor:

import ij.IJ;
import ij.plugin.frame.RoiManager;
import ij.measure.ResultsTable;

IJ.run("Blobs (25K)");
IJ.run("Invert LUT", "");
IJ.run("Convert to Mask", "");
RoiManager rm1 = RoiManager.getInstance();
if (rm1==null) rm1 = new RoiManager();
IJ.run("Set Measurements...", "area perimeter redirect=None decimal=3");
IJ.run("Analyze Particles...", "size=5-700000 circularity=0.10-1.00 show=Outlines display clear record include summarize add in_situ");
ResultsTable RT1 = ResultsTable.getResultsTable();
println(RT1.getValue("XStart", 1)); // prints 53.0

Does this print 53.0 into the output window in the script editor for you?


#7

Says “Error loading image”


#8

are you launching it from the script editor of Fiji?
have you selected groovy as language?
can your Fiji go on internet or there is a firewall?
because the blobs image is on a sample image loaded from the web by Fiji.

Emanuele Martini


#9

Yes it prints 53.0. There is some firewall issues with my system. So I downloaded the image from the FIJI website.


#10

Yeah, I launched from the script editor of FIJI. There were some issues with the firewall settings. So I downloaded the image and ran the code.


#11

I had another look at the ImageJ1.x JavaDoc:

public ResultsTable multiMeasure(ImagePlus imp)
This method measures the selected ROIs, or all ROIs if none are selected, on all the slices of a stack and returns a ResultsTable arranged with one row per slice.

Use the returned ResultsTable instance instead of using ResultsTable.getResultsTable():

ResultsTable RT1 = rm1.multiMeasure(CS);

#12

Same error: java.lang.IllegalArgumentException: "XStart" column not found

But now I am getting XStart and YStart columns in the console window.

I printed the Results just to check the heading labels on whether it exists in that object. What I found is that for each blob in the image there is separate column for Area and Perimeter and no XStart and YStart. Something like this:

Area1 Perim.1 Area2 Perim.2 Area3 Perim.3 Area4 Perim.4 Area5 Perim.5 and so on till the number of blobs in the image.


#13

Well, if you click the Multi Measure menu entry in the ROI Manager, you get a pop up that has a checkbox “One row per slice” that is enabled per default. In that case, you will get a table like you are describing. I assume that this is also the behavior of multiMeasure() (since there is no option to define how the results table is created).

Do you really need to Multi Measure, i.e. measure each ROI on each slice of a stack? If your images are not stacks and all you want to do is measure each ROI on a (possibly different) image, use:

// instead of rm1.multiMeasure(CS):
rm1.runCommand(CS, "Measure");
ResultsTable RT1 = ResultsTable.getResultsTable();

#14

I tried rm1.runCommand(CS, "Measure") too. But that gives me only Area and Perimeter in the Console window. Due to this, I still get the same error. I guess the problem is somewhere between the transfer of results from Analyze Particles to the ResultsTable. The values of the Results Window after Analyze Particles is being printed successfully in the console window as mentioned in the first part of this thread.