|
29 | 29 | import org.slf4j.LoggerFactory; |
30 | 30 | import qupath.bioimageio.spec.Model; |
31 | 31 | import qupath.bioimageio.spec.tensor.axes.Axes; |
32 | | -import qupath.bioimageio.spec.tensor.axes.Axis; |
33 | 32 | import qupath.bioimageio.spec.tensor.axes.SpaceAxes; |
34 | 33 | import qupath.fx.dialogs.Dialogs; |
35 | 34 | import qupath.lib.gui.QuPathGUI; |
|
41 | 40 | import qupath.opencv.ml.BioimageIoTools; |
42 | 41 | import qupath.opencv.ml.PatchClassifierParams; |
43 | 42 |
|
| 43 | + |
| 44 | +import static qupath.fx.utils.FXUtils.resetSpinnerNullToPrevious; |
| 45 | + |
| 46 | + |
44 | 47 | public class BioimageIoPane extends BorderPane { |
45 | 48 | private final QuPathGUI qupath; |
46 | 49 | private static final Logger logger = LoggerFactory.getLogger(BioimageIoPane.class); |
@@ -147,12 +150,25 @@ private void configurePixelSize(Model model) { |
147 | 150 | int yind = axString.indexOf("y"); |
148 | 151 | double xsize=0, ysize=0; |
149 | 152 | // if pixel size specified then use pixel size spinners |
| 153 | + PixelCalibration pixelCal = null; |
150 | 154 | if (xind != -1 && yind != -1) { |
151 | | - xsize = getSpaceAxisSize(axes[xind]); |
152 | | - ysize = getSpaceAxisSize(axes[yind]); |
| 155 | + if (axes[xind] instanceof SpaceAxes.SpaceAxis spaceAxisX && axes[yind] instanceof SpaceAxes.SpaceAxis spaceAxisY) { |
| 156 | + if (spaceAxisX.getUnit() != SpaceAxes.SpaceUnit.MICROMETER || spaceAxisY.getUnit() != SpaceAxes.SpaceUnit.MICROMETER) { |
| 157 | + logger.warn("Unsupported space unit {}, ignoring", spaceAxisX.getUnit()); |
| 158 | + pixelCal = PixelCalibration.getDefaultInstance(); |
| 159 | + } else { |
| 160 | + xsize = spaceAxisX.getScale(); |
| 161 | + ysize = spaceAxisY.getScale(); |
| 162 | + pixelCal = new PixelCalibration.Builder().pixelSizeMicrons(xsize, ysize).build(); |
| 163 | + } |
| 164 | + } else { |
| 165 | + logger.warn("X or Y axis is not a space axis and therefore has unknown pixel size"); |
| 166 | + } |
| 167 | + } else { |
| 168 | + pixelCal = PixelCalibration.getDefaultInstance(); |
153 | 169 | } |
154 | | - // if pixel size is not specified, remove the pixel size box |
155 | | - if (xsize == 0 || ysize == 0) { |
| 170 | + // if pixel calibration is default, remove the pixel size box |
| 171 | + if (pixelCal == PixelCalibration.getDefaultInstance()) { |
156 | 172 | resolutionSectionBox.getChildren().remove(pixelSizeBox); |
157 | 173 | } else { |
158 | 174 | // if using pixel size, we're not using downsample |
@@ -180,23 +196,14 @@ public Double fromString(String string) { |
180 | 196 | }); |
181 | 197 | pixelSizeSpinner.valueProperty().addListener((v, o, n) -> { |
182 | 198 | var pcBuilder = new PixelCalibration.Builder() |
183 | | - .pixelSizeMicrons(n.doubleValue(), n.doubleValue()); |
| 199 | + .pixelSizeMicrons(n, n); |
184 | 200 | builder.inputResolution(pcBuilder.build()); |
185 | 201 | }); |
186 | | - |
187 | 202 | downsampleSpinner.valueProperty().addListener((v, o, n) -> { |
188 | 203 | builder.inputResolution(PixelCalibration.getDefaultInstance(), n); |
189 | 204 | }); |
190 | | - } |
191 | | - |
192 | | - private double getSpaceAxisSize(Axis axis) { |
193 | | - if (axis instanceof SpaceAxes.SpaceAxis spaceAxis) { |
194 | | - if (spaceAxis.getUnit() != SpaceAxes.SpaceUnit.MICROMETER) { |
195 | | - logger.warn("Unknown space unit {}", spaceAxis.getUnit()); |
196 | | - } |
197 | | - return spaceAxis.getScale(); |
198 | | - } |
199 | | - return 0; |
| 205 | + resetSpinnerNullToPrevious(downsampleSpinner); |
| 206 | + resetSpinnerNullToPrevious(pixelSizeSpinner); |
200 | 207 | } |
201 | 208 |
|
202 | 209 | private void configureOutputClasses() { |
|
0 commit comments