ImagePlusUtil { public static double anisotropy(final ImagePlus image) { final Calibration cal = image.getCalibration(); final double w = cal.pixelWidth; final double h = cal.pixelHeight; final double widthHeightRatio = w > h ? w / h : h / w; final double widthHeightAnisotropy = Math.abs(1.0 - widthHeightRatio); if (!is3D(image)) { return widthHeightAnisotropy; } final double d = cal.pixelDepth; final double widthDepthRatio = w > d ? w / d : d / w; final double heightDepthRatio = h > d ? h / d : d / h; final double widthDepthAnisotropy = Math.abs(1.0 - widthDepthRatio); final double heightDepthAnisotropy = Math.abs(1.0 - heightDepthRatio); return Math.max(widthHeightAnisotropy, Math.max(widthDepthAnisotropy, heightDepthAnisotropy)); } private  ImagePlusUtil(); static double anisotropy(final ImagePlus image); static ImagePlus cleanDuplicate(final ImagePlus image); static boolean is3D(final ImagePlus image); static boolean isBinaryColour(final ImagePlus image);  }
@Test public void testAnisotropy() { final ImagePlus testImage = mock(ImagePlus.class); final Calibration anisotropicCalibration = new Calibration(); anisotropicCalibration.pixelWidth = 1; anisotropicCalibration.pixelHeight = 1; anisotropicCalibration.pixelDepth = 5; when(testImage.getCalibration()).thenReturn(anisotropicCalibration); when(testImage.getNSlices()).thenReturn(1); final double result = ImagePlusUtil.anisotropy(testImage); assertEquals("Anisotropy should be 0.0", 0.0, result, 1e-12); }
@Test public void testAnisotropy3D() { final double expected = 4.0; final ImagePlus testImage = mock(ImagePlus.class); final Calibration anisotropicCalibration = new Calibration(); anisotropicCalibration.pixelWidth = 1; anisotropicCalibration.pixelHeight = 2; anisotropicCalibration.pixelDepth = 5; when(testImage.getCalibration()).thenReturn(anisotropicCalibration); when(testImage.getNSlices()).thenReturn(10); final double result = ImagePlusUtil.anisotropy(testImage); assertEquals("Anisotropy should be " + expected, expected, result, 1e-12); }
@Test(expected = NullPointerException.class) public void testAnisotropyThrowsNPEIfImageNull() { ImagePlusUtil.anisotropy(null); }