|
12 | 12 | import qupath.lib.awt.common.BufferedImageTools; |
13 | 13 | import qupath.lib.common.GeneralTools; |
14 | 14 | import qupath.lib.gui.QuPathGUI; |
15 | | -import qupath.lib.gui.commands.SummaryMeasurementTableCommand; |
16 | 15 | import qupath.lib.gui.measure.ObservableMeasurementTableData; |
| 16 | +import qupath.lib.gui.measure.PathTableData; |
17 | 17 | import qupath.lib.gui.scripting.QPEx; |
18 | 18 | import qupath.lib.gui.tools.GuiTools; |
19 | 19 | import qupath.lib.gui.tools.GuiTools.SnapshotType; |
@@ -136,20 +136,41 @@ public static String getAnnotationMeasurementTable(ImageData<?> imageData) { |
136 | 136 | } |
137 | 137 |
|
138 | 138 | /** |
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. |
141 | 147 | * |
142 | 148 | * @param imageData the image containing the measurements to retrieve |
143 | 149 | * @param pathObjects the objects containing the measurements to retrieve |
144 | 150 | * @return a string representation of the measurement table |
| 151 | + * @see #getMeasurementTableRows(ImageData, Collection) |
145 | 152 | */ |
146 | 153 | 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) { |
147 | 168 | if (imageData == null || pathObjects == null || pathObjects.isEmpty()) { |
148 | | - return ""; |
| 169 | + return Collections.emptyList(); |
149 | 170 | } else { |
150 | 171 | var table = new ObservableMeasurementTableData(); |
151 | 172 | table.setImageData(imageData, pathObjects); |
152 | | - return SummaryMeasurementTableCommand.getTableModelString(table, "\t", Collections.emptyList()); |
| 173 | + return table.getRowStrings("\t", PathTableData.DEFAULT_DECIMAL_PLACES, null); |
153 | 174 | } |
154 | 175 | } |
155 | 176 |
|
|
0 commit comments