Skip to content

Commit 9d0d006

Browse files
petebankheadalanocallaghan
authored andcommitted
Update measurement table access
Adapt to changes from qupath/qupath#1753 See also qupath/qupath#1768
1 parent a191053 commit 9d0d006

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/main/java/qupath/ext/py4j/core/QuPathEntryPoint.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import qupath.lib.awt.common.BufferedImageTools;
1313
import qupath.lib.common.GeneralTools;
1414
import qupath.lib.gui.QuPathGUI;
15-
import qupath.lib.gui.commands.SummaryMeasurementTableCommand;
1615
import qupath.lib.gui.measure.ObservableMeasurementTableData;
16+
import qupath.lib.gui.measure.PathTableData;
1717
import qupath.lib.gui.scripting.QPEx;
1818
import qupath.lib.gui.tools.GuiTools;
1919
import qupath.lib.gui.tools.GuiTools.SnapshotType;
@@ -136,20 +136,41 @@ public static String getAnnotationMeasurementTable(ImageData<?> imageData) {
136136
}
137137

138138
/**
139-
* Return the measurement table in text format of the provided annotations/detections
140-
* of the provided image.
139+
* Return the measurement table in as a single tab-delimited string.
140+
* This is equivalent to joining all the rows provided by {@link #getMeasurementTableRows(ImageData, Collection)}
141+
* with newline characters.
142+
* <p>
143+
* Note that this may fail for very large tables, because the length of the text exceeds the
144+
* maximum length of a Java String.
145+
* In this case, using {@link #getMeasurementTableRows(ImageData, Collection)} is preferable,
146+
* or alternatively pass fewer objects to measure.
141147
*
142148
* @param imageData the image containing the measurements to retrieve
143149
* @param pathObjects the objects containing the measurements to retrieve
144150
* @return a string representation of the measurement table
151+
* @see #getMeasurementTableRows(ImageData, Collection)
145152
*/
146153
public static String getMeasurementTable(ImageData<?> imageData, Collection<? extends PathObject> pathObjects) {
154+
return String.join(System.lineSeparator(), getMeasurementTableRows(imageData, pathObjects));
155+
}
156+
157+
/**
158+
* Return the measurement table in a list of tab-delimited strings.
159+
* <p>
160+
* The first item corresponds to the header, while the rest correspond to objects in the provided collection.
161+
*
162+
* @param imageData the image containing the measurements to retrieve
163+
* @param pathObjects the objects containing the measurements to retrieve
164+
* @return a list of strings representing the measurement table
165+
* @see #getMeasurementTable(ImageData, Collection)
166+
*/
167+
public static List<String> getMeasurementTableRows(ImageData<?> imageData, Collection<? extends PathObject> pathObjects) {
147168
if (imageData == null || pathObjects == null || pathObjects.isEmpty()) {
148-
return "";
169+
return Collections.emptyList();
149170
} else {
150171
var table = new ObservableMeasurementTableData();
151172
table.setImageData(imageData, pathObjects);
152-
return SummaryMeasurementTableCommand.getTableModelString(table, "\t", Collections.emptyList());
173+
return table.getRowStrings("\t", PathTableData.DEFAULT_DECIMAL_PLACES, null);
153174
}
154175
}
155176

0 commit comments

Comments
 (0)