本文整理汇总了Java中ij.measure.Calibration类的典型用法代码示例。如果您正苦于以下问题:Java Calibration类的具体用法?Java Calibration怎么用?Java Calibration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Calibration类属于ij.measure包,在下文中一共展示了Calibration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gridCalculator
import ij.measure.Calibration; //导入依赖的package包/类
/**
* Generate a set of centroids padded from the image edges
*
* @param imp
* ImagePlus
* @param nCentroids
* Number of centroids to generate
* @param radius
* amount of padding between stack edges and centroid field
* @return nCentroids x 3 array of 3D coordinates
*/
private double[][] gridCalculator(final ImagePlus imp, final int nCentroids, final double radius) {
final Calibration cal = imp.getCalibration();
final double vW = cal.pixelWidth;
final double vH = cal.pixelHeight;
final double vD = cal.pixelDepth;
final int w = imp.getWidth();
final int h = imp.getHeight();
final int d = imp.getStackSize();
final double stackWidth = vW * w;
final double stackHeight = vH * h;
final double stackDepth = vD * d;
// strategy: n random coordinates within bounding box (easy, no bias.)
final double[][] gridCentroids = new double[nCentroids][3];
for (int n = 0; n < nCentroids; n++) {
gridCentroids[n][0] = Math.random() * (stackWidth - 2 * radius - 2 * vW) + radius;
gridCentroids[n][1] = Math.random() * (stackHeight - 2 * radius - 2 * vH) + radius;
gridCentroids[n][2] = Math.random() * (stackDepth - 2 * radius - 2 * vD) + radius;
}
// alternative: n regularly-spaced coordinates fitting
// within bounding box
// allegedly more efficient but could collide with periodic data
return gridCentroids;
}
示例2: scanco
import ij.measure.Calibration; //导入依赖的package包/类
private void scanco(final ImagePlus imp) throws IllegalArgumentException {
final String manufacturer = DicomTools.getTag(imp, "0008,0070");
if (manufacturer == null || !manufacturer.contains("SCANCO")) {
throw new IllegalArgumentException("File is not a SCANCO Medical DICOM");
}
final double slope = Double.parseDouble(DicomTools.getTag(imp, "0029,1004"));
final double intercept = Double.parseDouble(DicomTools.getTag(imp, "0029,1005"));
final double scaling = Double.parseDouble(DicomTools.getTag(imp, "0029,1000"));
final double c = intercept - 32768 * slope / scaling;
final double m = slope / scaling;
final double[] coef = { c, m };
final Calibration cal = imp.getCalibration();
cal.setFunction(Calibration.STRAIGHT_LINE, coef, "mg HA/ccm");
imp.setCalibration(cal);
imp.updateAndDraw();
}
示例3: testIsVoxelIsotropic
import ij.measure.Calibration; //导入依赖的package包/类
@Test
public void testIsVoxelIsotropic() throws Exception {
final ImagePlus testImage = mock(ImagePlus.class);
final Calibration anisotropicCalibration = new Calibration();
// 2D anisotropic image with 0 tolerance
anisotropicCalibration.pixelWidth = 2;
anisotropicCalibration.pixelHeight = 1;
when(testImage.getCalibration()).thenReturn(anisotropicCalibration);
when(testImage.getStackSize()).thenReturn(1);
boolean result = ImageCheck.isVoxelIsotropic(testImage, 0.0);
assertFalse("Image where width > height should not be isotropic", result);
// 2D image where anisotropy is within tolerance
result = ImageCheck.isVoxelIsotropic(testImage, 1.0);
assertTrue("Image should be isotropic if anisotropy is within tolerance", result);
// 3D image where depth anisotropy is beyond tolerance
anisotropicCalibration.pixelDepth = 1000;
when(testImage.getStackSize()).thenReturn(100);
result = ImageCheck.isVoxelIsotropic(testImage, 1.0);
assertFalse("Pixel depth too great to be anisotropic within tolerance", result);
}
示例4: initPointROIs
import ij.measure.Calibration; //导入依赖的package包/类
private boolean initPointROIs() {
// You can't have a RoiManager as a @Parameter with its own validator method
final RoiManager manager = RoiManager.getInstance();
if (manager == null) {
return false;
}
final Calibration calibration = inputImage.getCalibration();
final Function<Vector3d, Vector3d> calibrate = v -> {
v.x *= calibration.pixelWidth;
v.y *= calibration.pixelHeight;
v.z *= calibration.pixelDepth;
return v;
};
points = RoiManagerUtil.pointROICoordinates(manager).stream().filter(
p -> !RoiManagerUtil.isActiveOnAllSlices((int) p.z)).map(calibrate)
.collect(Collectors.toList());
return points.size() >= QUADRIC_TERMS;
}
示例5: testWarnAnisotropyReturnsTrueIfAnisotropicImageAndUserOK
import ij.measure.Calibration; //导入依赖的package包/类
@Test
@Category(org.bonej.wrapperPlugins.SlowWrapperTest.class)
public void testWarnAnisotropyReturnsTrueIfAnisotropicImageAndUserOK()
throws Exception
{
final ImagePlus imagePlus = mock(ImagePlus.class);
final Calibration anisotropicCalibration = new Calibration();
anisotropicCalibration.pixelWidth = 0.5;
when(imagePlus.getCalibration()).thenReturn(anisotropicCalibration);
final UIService uiService = mock(UIService.class);
when(uiService.showDialog(anyString(), any(MessageType.class), any()))
.thenReturn(OK_OPTION);
assertTrue(Common.warnAnisotropy(imagePlus, uiService));
verify(uiService, timeout(1000)).showDialog(anyString(), any(
MessageType.class), any());
}
示例6: testWarnAnisotropyReturnsFalseIfAnisotropicImageAndUserCancels
import ij.measure.Calibration; //导入依赖的package包/类
@Test
public void testWarnAnisotropyReturnsFalseIfAnisotropicImageAndUserCancels()
throws Exception
{
final ImagePlus imagePlus = mock(ImagePlus.class);
final Calibration anisotropicCalibration = new Calibration();
anisotropicCalibration.pixelWidth = 0.5;
when(imagePlus.getCalibration()).thenReturn(anisotropicCalibration);
final UIService uiService = mock(UIService.class);
when(uiService.showDialog(anyString(), any(MessageType.class), any()))
.thenReturn(CANCEL_OPTION);
assertFalse(Common.warnAnisotropy(imagePlus, uiService));
verify(uiService, timeout(1000)).showDialog(anyString(), any(
MessageType.class), any());
}
示例7: testWarnAnisotropyReturnsFalseIfAnisotropicImageAndUserCloses
import ij.measure.Calibration; //导入依赖的package包/类
@Test
@Category(org.bonej.wrapperPlugins.SlowWrapperTest.class)
public void testWarnAnisotropyReturnsFalseIfAnisotropicImageAndUserCloses()
throws Exception
{
final ImagePlus imagePlus = mock(ImagePlus.class);
final Calibration anisotropicCalibration = new Calibration();
anisotropicCalibration.pixelWidth = 0.5;
when(imagePlus.getCalibration()).thenReturn(anisotropicCalibration);
final UIService uiService = mock(UIService.class);
when(uiService.showDialog(anyString(), any(MessageType.class), any()))
.thenReturn(CLOSED_OPTION);
assertFalse(Common.warnAnisotropy(imagePlus, uiService));
verify(uiService, timeout(1000)).showDialog(anyString(), any(
MessageType.class), any());
}
示例8: testRun
import ij.measure.Calibration; //导入依赖的package包/类
@Test
public void testRun() throws Exception {
// SETUP
final String expectedTitle = "Skeleton of Test";
final ImagePlus imagePlus = NewImage.createImage("Test", 5, 5, 5, 8, 1);
final Calibration calibration = new Calibration();
calibration.setUnit("my unit");
imagePlus.setCalibration(calibration);
// EXECUTE
final CommandModule module = IMAGE_J.command().run(SkeletoniseWrapper.class,
true, "inputImage", imagePlus).get();
// VERIFY
final ImagePlus skeleton = (ImagePlus) module.getOutput("skeleton");
assertNotNull("Skeleton image should not be null", skeleton);
assertEquals("Skeleton has wrong title", expectedTitle, skeleton
.getTitle());
assertEquals("Skeleton should have same calibration", "my unit", skeleton
.getCalibration().getUnit());
assertNotSame("Original image should not have been overwritten",
imagePlus, skeleton);
}
示例9: anisotropy
import ij.measure.Calibration; //导入依赖的package包/类
/**
* Calculates the degree of anisotropy in the image, i.e. the maximum
* difference in the calibrations of the dimensions.
*
* @param image an ImageJ1 style {@link ImagePlus}.
* @return Anisotropy fraction [0.0, Double.MAX_VALUE], an isotropic image
* returns 0.0 Returns Double.NaN if image == null.
*/
public static double anisotropy(final ImagePlus image) {
if (image == null) {
return Double.NaN;
}
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));
}
示例10: testAnisotropy3D
import ij.measure.Calibration; //导入依赖的package包/类
@Test
public void testAnisotropy3D() throws Exception {
final double expected = 4.0;
// Mock an anisotropic 3D image
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);
}
示例11: testAnisotropy
import ij.measure.Calibration; //导入依赖的package包/类
@Test
public void testAnisotropy() throws Exception {
// Mock an isotropic 2D image
final ImagePlus testImage = mock(ImagePlus.class);
final Calibration anisotropicCalibration = new Calibration();
anisotropicCalibration.pixelWidth = 1;
anisotropicCalibration.pixelHeight = 1;
// Should not care about pixelDepth because image is 2D
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);
}
示例12: convertToPathObject
import ij.measure.Calibration; //导入依赖的package包/类
public static PathObject convertToPathObject(ImagePlus imp, ImageServer<?> server, Roi roi, double downsampleFactor, boolean makeDetection, int c, int z, int t) {
Calibration cal = imp.getCalibration();
ROI pathROI = ROIConverterIJ.convertToPathROI(roi, cal, downsampleFactor, c, z, t);
if (pathROI == null)
return null;
PathObject pathObject;
if (makeDetection && !(pathROI instanceof PointsROI))
pathObject = new PathDetectionObject(pathROI);
else
pathObject = new PathAnnotationObject(pathROI);
Color color = roi.getStrokeColor();
if (color == null)
color = Roi.getColor();
pathObject.setColorRGB(color.getRGB());
if (roi.getName() != null)
pathObject.setName(roi.getName());
return pathObject;
}
示例13: convertToPathROI
import ij.measure.Calibration; //导入依赖的package包/类
/**
* Create a ROI from an ImageJ Roi.
*
* @param pathROI
* @param pathImage
* @return
*/
public static ROI convertToPathROI(Roi roi, Calibration cal, double downsampleFactor, final int c, final int z, final int t) {
// if (roi.getType() == Roi.POLYGON || roi.getType() == Roi.TRACED_ROI)
// return convertToPolygonROI((PolygonRoi)roi, cal, downsampleFactor);
if (roi.getType() == Roi.RECTANGLE && roi.getCornerDiameter() == 0)
return getRectangleROI(roi, cal, downsampleFactor, c, z, t);
if (roi.getType() == Roi.OVAL)
return convertToEllipseROI(roi, cal, downsampleFactor, c, z, t);
if (roi instanceof Line)
return convertToLineROI((Line)roi, cal, downsampleFactor, c, z, t);
if (roi instanceof PointRoi)
return convertToPointROI((PolygonRoi)roi, cal, downsampleFactor, c, z, t);
// if (roi instanceof ShapeRoi)
// return convertToAreaROI((ShapeRoi)roi, cal, downsampleFactor);
// // Shape ROIs should be able to handle most eventualities
if (roi instanceof ShapeRoi)
return convertToAreaROI((ShapeRoi)roi, cal, downsampleFactor, c, z, t);
if (roi.isArea())
return convertToPolygonOrAreaROI(roi, cal, downsampleFactor, c, z, t);
// TODO: Integrate ROI not supported exception...?
return null;
}
示例14: testReadOffset
import ij.measure.Calibration; //导入依赖的package包/类
@Test
public void testReadOffset() throws Exception {
final File inFile = new File("test/data/Issue_001+2/fixed.mhd");
final ImagePlus[] imps = MiDecoder.open(inFile);
assertNotNull(imps);
assertEquals(1, imps.length);
final ImagePlus imp = imps[0];
assertEquals("width", 305, imp.getWidth());
assertEquals("heights", 311, imp.getHeight());
assertEquals("slices", 11, imp.getStackSize());
assertEquals("image type", ImagePlus.GRAY32, imp.getType());
// Test if origin is read correctly, Issue #1.
final Calibration cal = imp.getCalibration();
final double elementSpacing = 0.04;
assertEquals("xOrigin", 0 / elementSpacing, cal.xOrigin, 0.001);
assertEquals("yOrigin", 0 / elementSpacing, cal.yOrigin, 0.001);
assertEquals("zOrigin", 10.4 / elementSpacing, cal.zOrigin, 0.001);
}
示例15: setThreshold
import ij.measure.Calibration; //导入依赖的package包/类
/** Sets the lower and upper threshold levels of the specified image and updates the display using
the specified <code>displayMode</code> ("Red", "Black & White", "Over/Under" or "No Update"). */
public static void setThreshold(ImagePlus img, double lowerThreshold, double upperThreshold, String displayMode) {
int mode = ImageProcessor.RED_LUT;
if (displayMode!=null) {
displayMode = displayMode.toLowerCase(Locale.US);
if (displayMode.indexOf("black")!=-1)
mode = ImageProcessor.BLACK_AND_WHITE_LUT;
else if (displayMode.indexOf("over")!=-1)
mode = ImageProcessor.OVER_UNDER_LUT;
else if (displayMode.indexOf("no")!=-1)
mode = ImageProcessor.NO_LUT_UPDATE;
}
Calibration cal = img.getCalibration();
lowerThreshold = cal.getRawValue(lowerThreshold);
upperThreshold = cal.getRawValue(upperThreshold);
img.getProcessor().setThreshold(lowerThreshold, upperThreshold, mode);
if (mode != ImageProcessor.NO_LUT_UPDATE) {
img.getProcessor().setLutAnimation(true);
img.updateAndDraw();
}
}