@Test public void testCalibratedSpatialElementSizeUnitsInconvertible() { final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, "cm"); final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, ""); final Img<DoubleType> img = IMAGE_J.op().create().img(new int[] { 10, 10 }); final ImgPlus<DoubleType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis); final double result = ElementUtil.calibratedSpatialElementSize(imgPlus, unitService); assertEquals("Size should be NaN if unit inconvertible", Double.NaN, result, 1e-12); }
public static <T extends AnnotatedSpace<CalibratedAxis>> double calibratedSpatialElementSize(final T space, final UnitService unitService) { final Optional<String> optional = AxisUtils.getSpatialUnit(space, unitService); if (!optional.isPresent() || hasNonLinearSpatialAxes(space)) { return Double.NaN; } final double elementSize = spatialAxisStream(space).map(a -> a.averageScale( 0, 1)).reduce((x, y) -> x * y).orElse(0.0); final String outputUnit = optional.get().replaceFirst("^µ[mM]$", "um"); if (outputUnit.isEmpty()) { return elementSize; } final List<CalibratedAxis> axes = spatialAxisStream(space).collect( Collectors.toList()); double unitCoeff = 1.0; for (int i = 1; i < axes.size(); i++) { final String inputUnit = axes.get(i).unit().replaceFirst("^µ[mM]$", "um"); final double conversion = unitService.value(1.0, inputUnit, outputUnit); unitCoeff *= conversion; } return elementSize * unitCoeff; }
ElementUtil { public static <T extends AnnotatedSpace<CalibratedAxis>> double calibratedSpatialElementSize(final T space, final UnitService unitService) { final Optional<String> optional = AxisUtils.getSpatialUnit(space, unitService); if (!optional.isPresent() || hasNonLinearSpatialAxes(space)) { return Double.NaN; } final double elementSize = spatialAxisStream(space).map(a -> a.averageScale( 0, 1)).reduce((x, y) -> x * y).orElse(0.0); final String outputUnit = optional.get().replaceFirst("^µ[mM]$", "um"); if (outputUnit.isEmpty()) { return elementSize; } final List<CalibratedAxis> axes = spatialAxisStream(space).collect( Collectors.toList()); double unitCoeff = 1.0; for (int i = 1; i < axes.size(); i++) { final String inputUnit = axes.get(i).unit().replaceFirst("^µ[mM]$", "um"); final double conversion = unitService.value(1.0, inputUnit, outputUnit); unitCoeff *= conversion; } return elementSize * unitCoeff; } }
ElementUtil { public static <T extends AnnotatedSpace<CalibratedAxis>> double calibratedSpatialElementSize(final T space, final UnitService unitService) { final Optional<String> optional = AxisUtils.getSpatialUnit(space, unitService); if (!optional.isPresent() || hasNonLinearSpatialAxes(space)) { return Double.NaN; } final double elementSize = spatialAxisStream(space).map(a -> a.averageScale( 0, 1)).reduce((x, y) -> x * y).orElse(0.0); final String outputUnit = optional.get().replaceFirst("^µ[mM]$", "um"); if (outputUnit.isEmpty()) { return elementSize; } final List<CalibratedAxis> axes = spatialAxisStream(space).collect( Collectors.toList()); double unitCoeff = 1.0; for (int i = 1; i < axes.size(); i++) { final String inputUnit = axes.get(i).unit().replaceFirst("^µ[mM]$", "um"); final double conversion = unitService.value(1.0, inputUnit, outputUnit); unitCoeff *= conversion; } return elementSize * unitCoeff; } private  ElementUtil(); }
ElementUtil { public static <T extends AnnotatedSpace<CalibratedAxis>> double calibratedSpatialElementSize(final T space, final UnitService unitService) { final Optional<String> optional = AxisUtils.getSpatialUnit(space, unitService); if (!optional.isPresent() || hasNonLinearSpatialAxes(space)) { return Double.NaN; } final double elementSize = spatialAxisStream(space).map(a -> a.averageScale( 0, 1)).reduce((x, y) -> x * y).orElse(0.0); final String outputUnit = optional.get().replaceFirst("^µ[mM]$", "um"); if (outputUnit.isEmpty()) { return elementSize; } final List<CalibratedAxis> axes = spatialAxisStream(space).collect( Collectors.toList()); double unitCoeff = 1.0; for (int i = 1; i < axes.size(); i++) { final String inputUnit = axes.get(i).unit().replaceFirst("^µ[mM]$", "um"); final double conversion = unitService.value(1.0, inputUnit, outputUnit); unitCoeff *= conversion; } return elementSize * unitCoeff; } private  ElementUtil(); static double calibratedSpatialElementSize(final T space, final UnitService unitService); static boolean isBinary(
		final IterableInterval<T> interval); }
ElementUtil { public static <T extends AnnotatedSpace<CalibratedAxis>> double calibratedSpatialElementSize(final T space, final UnitService unitService) { final Optional<String> optional = AxisUtils.getSpatialUnit(space, unitService); if (!optional.isPresent() || hasNonLinearSpatialAxes(space)) { return Double.NaN; } final double elementSize = spatialAxisStream(space).map(a -> a.averageScale( 0, 1)).reduce((x, y) -> x * y).orElse(0.0); final String outputUnit = optional.get().replaceFirst("^µ[mM]$", "um"); if (outputUnit.isEmpty()) { return elementSize; } final List<CalibratedAxis> axes = spatialAxisStream(space).collect( Collectors.toList()); double unitCoeff = 1.0; for (int i = 1; i < axes.size(); i++) { final String inputUnit = axes.get(i).unit().replaceFirst("^µ[mM]$", "um"); final double conversion = unitService.value(1.0, inputUnit, outputUnit); unitCoeff *= conversion; } return elementSize * unitCoeff; } private  ElementUtil(); static double calibratedSpatialElementSize(final T space, final UnitService unitService); static boolean isBinary(
		final IterableInterval<T> interval);  }