Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/main/java/qupath/ext/py4j/core/QuPathEntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import qupath.lib.awt.common.BufferedImageTools;
import qupath.lib.common.GeneralTools;
import qupath.lib.gui.QuPathGUI;
import qupath.lib.gui.commands.SummaryMeasurementTableCommand;
import qupath.lib.gui.measure.ObservableMeasurementTableData;
import qupath.lib.gui.measure.PathTableData;
import qupath.lib.gui.scripting.QPEx;
import qupath.lib.gui.tools.GuiTools;
import qupath.lib.gui.tools.GuiTools.SnapshotType;
Expand Down Expand Up @@ -136,20 +136,41 @@ public static String getAnnotationMeasurementTable(ImageData<?> imageData) {
}

/**
* Return the measurement table in text format of the provided annotations/detections
* of the provided image.
* Return the measurement table in as a single tab-delimited string.
* This is equivalent to joining all the rows provided by {@link #getMeasurementTableRows(ImageData, Collection)}
* with newline characters.
* <p>
* Note that this may fail for very large tables, because the length of the text exceeds the
* maximum length of a Java String.
* In this case, using {@link #getMeasurementTableRows(ImageData, Collection)} is preferable,
* or alternatively pass fewer objects to measure.
*
* @param imageData the image containing the measurements to retrieve
* @param pathObjects the objects containing the measurements to retrieve
* @return a string representation of the measurement table
* @see #getMeasurementTableRows(ImageData, Collection)
*/
public static String getMeasurementTable(ImageData<?> imageData, Collection<? extends PathObject> pathObjects) {
return String.join(System.lineSeparator(), getMeasurementTableRows(imageData, pathObjects));
}

/**
* Return the measurement table in a list of tab-delimited strings.
* <p>
* The first item corresponds to the header, while the rest correspond to objects in the provided collection.
*
* @param imageData the image containing the measurements to retrieve
* @param pathObjects the objects containing the measurements to retrieve
* @return a list of strings representing the measurement table
* @see #getMeasurementTable(ImageData, Collection)
*/
public static List<String> getMeasurementTableRows(ImageData<?> imageData, Collection<? extends PathObject> pathObjects) {
if (imageData == null || pathObjects == null || pathObjects.isEmpty()) {
return "";
return Collections.emptyList();
} else {
var table = new ObservableMeasurementTableData();
table.setImageData(imageData, pathObjects);
return SummaryMeasurementTableCommand.getTableModelString(table, "\t", Collections.emptyList());
return table.getRowStrings("\t", PathTableData.DEFAULT_DECIMAL_PLACES, null);
}
}

Expand Down
Loading