Search in sources :

Example 26 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class CopyImgTest method createData.

@Before
public void createData() {
    input = new ArrayImgFactory<DoubleType>().create(new int[] { 120, 100 }, new DoubleType());
    final MersenneTwisterFast r = new MersenneTwisterFast(System.currentTimeMillis());
    final Cursor<DoubleType> inc = input.cursor();
    while (inc.hasNext()) {
        inc.next().set(r.nextDouble());
    }
}
Also used : MersenneTwisterFast(org.scijava.util.MersenneTwisterFast) DoubleType(net.imglib2.type.numeric.real.DoubleType) ArrayImgFactory(net.imglib2.img.array.ArrayImgFactory) Before(org.junit.Before)

Example 27 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class CopyTypeTest method copyTypeWithOutputTest.

@Test
public void copyTypeWithOutputTest() {
    DoubleType out = new DoubleType();
    ops.run(CopyType.class, out, dt);
    assertEquals(dt.get(), out.get(), 0.0);
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 28 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class CreateKernelDiffractionTest method testKernelDiffraction3D.

/**
 * Validate generation of a 3D diffraction kernel against a comparable result
 * from <a href="http://bigwww.epfl.ch/algorithms/psfgenerator/">
 * PSFGenerator</a>.
 * <p>
 * It is worth noting that results are only comparable between the two when
 * using a particle position relative to the coverslip of 0. This is because
 * imagej-ops automatically crops and centers kernels produced by the Fast
 * Gibson-Lanni implementation in {@link DefaultCreateKernelGibsonLanni} while
 * the Gibson &amp; Lanni kernels produced by PSFGenerator are not. See this
 * github issue
 * <a href="https://github.com/imagej/imagej-ops/issues/550">thread</a> for
 * more details.
 * </p>
 * <p>
 * It is also worth noting that when using a particle position of 0, the model
 * degenerates to a standard Born &amp; Wolf PSF model [1].
 * </p>
 * <h3>References:</h3>
 * <ol>
 * <li>Jizhou Li, Feng Xue, and Thierry Blu, "Fast and accurate
 * three-dimensional point spread function computation for fluorescence
 * microscopy," J. Opt. Soc. Am. A 34, 1029-1034 (2017)</li>
 * </ol>
 */
@Test
public void testKernelDiffraction3D() {
    final Dimensions dims = new FinalDimensions(16, 16, 8);
    // numerical aperture
    final double NA = 1.4;
    // wavelength
    final double lambda = 610E-09;
    // specimen refractive index
    final double ns = 1.33;
    // immersion refractive index, experimental
    final double ni = 1.5;
    // lateral pixel size
    final double resLateral = 100E-9;
    // axial pixel size
    final double resAxial = 250E-9;
    // pixel type of created kernel
    final DoubleType type = new DoubleType();
    // NB: It is important that this remain 0 for comparison to PSFGenerator.
    // position of particle
    final double pZ = 0D;
    final Img<DoubleType> kernel = ops.create().kernelDiffraction(dims, NA, lambda, ns, ni, resLateral, resAxial, pZ, type);
    // The following image used for comparison was generated via PSFGenerator
    // with these arguments (where any not mentioned were left at default):
    // Optical Model: "Gibson & Lanni 3D Optical Model"
    // Particle position Z: 0
    // Wavelength: 610 (nm)
    // Pixelsize XY: 100 (nm)
    // Z-step: 250 (nm)
    // Size XYZ: 16, 16, 8
    Img<DoubleType> expected = openDoubleImg("kern3d1.tif");
    assertArrayEquals(asArray(expected), asArray(kernel), 1e-4);
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) DoubleType(net.imglib2.type.numeric.real.DoubleType) FinalDimensions(net.imglib2.FinalDimensions) Dimensions(net.imglib2.Dimensions) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 29 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class CreateKernelDiffractionTest method testKernelDiffraction2D.

@Test
public void testKernelDiffraction2D() {
    final Dimensions dims = new FinalDimensions(10, 10);
    // numerical aperture
    final double NA = 1.4;
    // wavelength
    final double lambda = 610E-09;
    // specimen refractive index
    final double ns = 1.33;
    // immersion refractive index, experimental
    final double ni = 1.5;
    // lateral pixel size
    final double resLateral = 100E-9;
    // axial pixel size
    final double resAxial = 250E-9;
    // position of particle
    final double pZ = 2000E-9D;
    // pixel type of created kernel
    final DoubleType type = new DoubleType();
    final // 
    Img<DoubleType> kernel = ops.create().kernelDiffraction(dims, NA, lambda, ns, ni, resLateral, resAxial, pZ, type);
    final double[] expected = { 0.03298495871588273, 0.04246786111102021, 0.0543588031627261, 0.06650574371357207, 0.07370280610722534, 0.07370280610722534, 0.06650574371357207, 0.0543588031627261, 0.04246786111102021, 0.03298495871588273, 0.04246786111102021, 0.05962205221267819, 0.08320071670150801, 0.10800022978800021, 0.1247473245002288, 0.1247473245002288, 0.10800022978800021, 0.08320071670150801, 0.05962205221267819, 0.04246786111102021, 0.0543588031627261, 0.08320071670150801, 0.1247473245002288, 0.1971468112729564, 0.2691722397359577, 0.2691722397359577, 0.1971468112729564, 0.1247473245002288, 0.08320071670150801, 0.0543588031627261, 0.06650574371357207, 0.10800022978800021, 0.1971468112729564, 0.40090474481128285, 0.6227157103102976, 0.6227157103102976, 0.40090474481128285, 0.1971468112729564, 0.10800022978800021, 0.06650574371357207, 0.07370280610722534, 0.1247473245002288, 0.2691722397359577, 0.6227157103102976, 1.0, 1.0, 0.6227157103102976, 0.2691722397359577, 0.1247473245002288, 0.07370280610722534, 0.07370280610722534, 0.1247473245002288, 0.2691722397359577, 0.6227157103102976, 1.0, 1.0, 0.6227157103102976, 0.2691722397359577, 0.1247473245002288, 0.07370280610722534, 0.06650574371357207, 0.10800022978800021, 0.1971468112729564, 0.40090474481128285, 0.6227157103102976, 0.6227157103102976, 0.40090474481128285, 0.1971468112729564, 0.10800022978800021, 0.06650574371357207, 0.0543588031627261, 0.08320071670150801, 0.1247473245002288, 0.1971468112729564, 0.2691722397359577, 0.2691722397359577, 0.1971468112729564, 0.1247473245002288, 0.08320071670150801, 0.0543588031627261, 0.04246786111102021, 0.05962205221267819, 0.08320071670150801, 0.10800022978800021, 0.1247473245002288, 0.1247473245002288, 0.10800022978800021, 0.08320071670150801, 0.05962205221267819, 0.04246786111102021, 0.03298495871588273, 0.04246786111102021, 0.0543588031627261, 0.06650574371357207, 0.07370280610722534, 0.07370280610722534, 0.06650574371357207, 0.0543588031627261, 0.04246786111102021, 0.03298495871588273 };
    assertArrayEquals(expected, asArray(kernel), 1e-4);
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) DoubleType(net.imglib2.type.numeric.real.DoubleType) FinalDimensions(net.imglib2.FinalDimensions) Dimensions(net.imglib2.Dimensions) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 30 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class DefaultDirectionalityFeature method compute.

@SuppressWarnings("unchecked")
@Override
public void compute(final RandomAccessibleInterval<I> input, final O output) {
    // List to store all directions occuring within the image on borders
    ArrayList<DoubleType> dirList = new ArrayList<>();
    // Dimension of input region
    long[] dims = new long[input.numDimensions()];
    input.dimensions(dims);
    // create image for derivations in x and y direction
    Img<I> derX = imgCreator.calculate(input);
    Img<I> derY = imgCreator.calculate(input);
    // calculate derivations in x and y direction
    PartialDerivative.gradientCentralDifference2(Views.extendMirrorSingle(input), derX, 0);
    PartialDerivative.gradientCentralDifference2(Views.extendMirrorSingle(input), derY, 1);
    // calculate theta at each position: theta = atan(dX/dY) + pi/2
    Cursor<I> cX = derX.cursor();
    Cursor<I> cY = derY.cursor();
    // for each position calculate magnitude and direction
    while (cX.hasNext()) {
        cX.next();
        cY.next();
        double dx = cX.get().getRealDouble();
        double dy = cY.get().getRealDouble();
        double dir = 0.0;
        double mag = 0.0;
        mag = Math.sqrt(dx * dx + dy * dy);
        if (dx != 0 && mag > 0.0) {
            dir = Math.atan(dy / dx) + Math.PI / 2;
            dirList.add(new DoubleType(dir));
        }
    }
    // No directions: output is zero
    if (dirList.isEmpty()) {
        output.setReal(0.0);
    } else // Otherwise compute histogram over all occuring directions
    // and calculate inverse second moment on it as output
    {
        Histogram1d<Integer> hist = histOp.calculate(dirList);
        double std = stdOp.calculate(hist).getRealDouble();
        output.setReal(1 / std);
    }
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) ArrayList(java.util.ArrayList)

Aggregations

DoubleType (net.imglib2.type.numeric.real.DoubleType)185 Test (org.junit.Test)123 AbstractOpTest (net.imagej.ops.AbstractOpTest)111 LongType (net.imglib2.type.numeric.integer.LongType)37 MersenneTwisterFast (org.scijava.util.MersenneTwisterFast)19 ArrayList (java.util.ArrayList)14 Dataset (net.imagej.Dataset)14 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)13 Img (net.imglib2.img.Img)10 PointSet (net.imglib2.ops.pointset.PointSet)10 Ops (net.imagej.ops.Ops)9 HyperVolumePointSet (net.imglib2.ops.pointset.HyperVolumePointSet)9 Overlay (net.imagej.overlay.Overlay)8 FinalDimensions (net.imglib2.FinalDimensions)8 FinalInterval (net.imglib2.FinalInterval)8 BitType (net.imglib2.type.logic.BitType)8 DatasetView (net.imagej.display.DatasetView)7 Dimensions (net.imglib2.Dimensions)7 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)7 RealLocalizable (net.imglib2.RealLocalizable)6