Search in sources :

Example 46 with ByteType

use of net.imglib2.type.numeric.integer.ByteType in project imagej-ops by imagej.

the class NonLinearFiltersTest method testMedianFilter.

/**
 * @see MedianFilterOp
 * @see DefaultMedianFilter
 */
@Test
public void testMedianFilter() {
    ops.run(MedianFilterOp.class, out, in, shape, oobFactory);
    ArrayList<ByteType> items = new ArrayList<>();
    NeighborhoodsIterableInterval<ByteType> neighborhoods = shape.neighborhoods(Views.interval(Views.extendMirrorSingle(in), in));
    for (ByteType t : neighborhoods.firstElement()) {
        items.add(t.copy());
    }
    Collections.sort(items);
    assertEquals(items.get(5).get(), out.firstElement().get());
}
Also used : ArrayList(java.util.ArrayList) ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 47 with ByteType

use of net.imglib2.type.numeric.integer.ByteType in project imagej-ops by imagej.

the class ConvolveTest method testConvolveMethodSelection.

/**
 * Tests that the correct convolver is selected when using a small kernel.
 */
@Test
public void testConvolveMethodSelection() {
    final Img<ByteType> in = new ArrayImgFactory<ByteType>().create(new int[] { 20, 20 }, new ByteType());
    // use a small kernel
    int[] kernelSize = new int[] { 3, 3 };
    Img<FloatType> kernel = new ArrayImgFactory<FloatType>().create(kernelSize, new FloatType());
    Op op = ops.op(Ops.Filter.Convolve.class, in, kernel);
    // we should get ConvolveNaive
    assertSame(ConvolveNaiveF.class, op.getClass());
    // make sure it runs
    @SuppressWarnings("unchecked") final Img<FloatType> out1 = (Img<FloatType>) ops.run(ConvolveNaiveF.class, in, kernel);
    assertEquals(out1.dimension(0), 20);
    // use a bigger kernel
    kernelSize = new int[] { 30, 30 };
    kernel = new ArrayImgFactory<FloatType>().create(kernelSize, new FloatType());
    op = ops.op(Ops.Filter.Convolve.class, in, kernel);
    // this time we should get ConvolveFFT
    assertSame(ConvolveFFTF.class, op.getClass());
    // make sure it runs
    @SuppressWarnings("unchecked") final Img<FloatType> out2 = (Img<FloatType>) ops.run(ConvolveFFTF.class, in, kernel);
    assertEquals(out2.dimension(0), 20);
}
Also used : Op(net.imagej.ops.Op) BinaryFunctionOp(net.imagej.ops.special.function.BinaryFunctionOp) UnaryFunctionOp(net.imagej.ops.special.function.UnaryFunctionOp) Img(net.imglib2.img.Img) ByteType(net.imglib2.type.numeric.integer.ByteType) ArrayImgFactory(net.imglib2.img.array.ArrayImgFactory) FloatType(net.imglib2.type.numeric.real.FloatType) ComplexFloatType(net.imglib2.type.numeric.complex.ComplexFloatType) Ops(net.imagej.ops.Ops) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 48 with ByteType

use of net.imglib2.type.numeric.integer.ByteType in project imagej-ops by imagej.

the class ConvertIIsTest method createImages.

@Before
public void createImages() {
    final FinalDimensions dims = FinalDimensions.wrap(new long[] { 10, 10 });
    in = ops.create().img(dims, new ShortType());
    addNoise(in);
    out = ops.create().img(dims, new ByteType());
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) ShortType(net.imglib2.type.numeric.integer.ShortType) ByteType(net.imglib2.type.numeric.integer.ByteType) Before(org.junit.Before)

Example 49 with ByteType

use of net.imglib2.type.numeric.integer.ByteType in project vcell by virtualcell.

the class ConstructTIRFGeometry method run.

@Override
public void run() {
    // Calculate constant d in TIRF exponential decay function
    // Angle of incidence in radians
    theta = theta * 2 * Math.PI / 360;
    // Refractive index of glass
    final double n1 = 1.52;
    // Refractive index of cytosol
    final double n2 = 1.38;
    final double d = lambda * Math.pow((Math.pow(n1, 2) * Math.pow(Math.sin(theta), 2) - Math.pow(n2, 2)), -0.5) / (4 * Math.PI);
    System.out.println("d: " + d);
    final double fluorPerMolecule = 250;
    // Get frame of interest to define geometry
    long maxX = data.dimension(0) - 1;
    long maxY = data.dimension(1) - 1;
    Interval interval = Intervals.createMinMax(0, 0, sliceIndex, maxX, maxY, sliceIndex);
    RandomAccessibleInterval<T> croppedRAI = ops.transform().crop(data, interval, true);
    // Subtract lowest pixel value
    IterableInterval<T> dataII = Views.iterable(croppedRAI);
    double min = ops.stats().min(dataII).getRealDouble();
    Cursor<T> dataCursor = dataII.cursor();
    while (dataCursor.hasNext()) {
        double val = dataCursor.next().getRealDouble();
        dataCursor.get().setReal(val - min);
    }
    // Perform Gaussian blur
    RandomAccessibleInterval<T> blurredRAI = ops.filter().gauss(croppedRAI, 2);
    IterableInterval<T> blurredII = Views.iterable(blurredRAI);
    // Segment slice by threshold and fill holes
    IterableInterval<BitType> thresholded = ops.threshold().huang(blurredII);
    Img<BitType> thresholdedImg = ops.convert().bit(thresholded);
    RandomAccessibleInterval<BitType> thresholdedRAI = ops.morphology().fillHoles(thresholdedImg);
    // Get the largest region
    RandomAccessibleInterval<LabelingType<ByteType>> labeling = ops.labeling().cca(thresholdedRAI, ConnectedComponents.StructuringElement.EIGHT_CONNECTED);
    LabelRegions<ByteType> labelRegions = new LabelRegions<>(labeling);
    Iterator<LabelRegion<ByteType>> iterator = labelRegions.iterator();
    LabelRegion<ByteType> maxRegion = iterator.next();
    while (iterator.hasNext()) {
        LabelRegion<ByteType> currRegion = iterator.next();
        if (currRegion.size() > maxRegion.size()) {
            maxRegion = currRegion;
        }
    }
    // Generate z index map
    double iMax = ops.stats().max(dataII).getRealDouble();
    Img<UnsignedShortType> dataImg = ops.convert().uint16(dataII);
    Img<UnsignedShortType> zMap = ops.convert().uint16(ops.create().img(dataII));
    LabelRegionCursor cursor = maxRegion.localizingCursor();
    RandomAccess<UnsignedShortType> zMapRA = zMap.randomAccess();
    RandomAccess<UnsignedShortType> dataRA = dataImg.randomAccess();
    while (cursor.hasNext()) {
        cursor.fwd();
        zMapRA.setPosition(cursor);
        dataRA.setPosition(cursor);
        double val = dataRA.get().getRealDouble();
        // Log of 0 is undefined
        if (val < 1) {
            val = 1;
        }
        int z = (int) Math.round(-d * Math.log(val / iMax) / zRes);
        zMapRA.get().set(z);
    }
    System.out.println("6");
    // Use map to construct 3D geometry
    // Add 5 slices of padding on top
    int maxZ = (int) ops.stats().max(zMap).getRealDouble() + 5;
    long[] resultDimensions = { maxX + 1, maxY + 1, maxZ };
    Img<BitType> result = new ArrayImgFactory<BitType>().create(resultDimensions, new BitType());
    RandomAccess<BitType> resultRA = result.randomAccess();
    System.out.println(maxZ);
    cursor.reset();
    while (cursor.hasNext()) {
        cursor.fwd();
        zMapRA.setPosition(cursor);
        int zIndex = zMapRA.get().get();
        int[] position = { cursor.getIntPosition(0), cursor.getIntPosition(1), zIndex };
        while (position[2] < maxZ) {
            resultRA.setPosition(position);
            resultRA.get().set(true);
            position[2]++;
        }
    }
    output = datasetService.create(result);
    CalibratedAxis[] axes = new DefaultLinearAxis[] { new DefaultLinearAxis(Axes.X), new DefaultLinearAxis(Axes.Y), new DefaultLinearAxis(Axes.Z) };
    output.setAxes(axes);
    System.out.println("Done constructing geometry");
}
Also used : ByteType(net.imglib2.type.numeric.integer.ByteType) DefaultLinearAxis(net.imagej.axis.DefaultLinearAxis) BitType(net.imglib2.type.logic.BitType) LabelRegionCursor(net.imglib2.roi.labeling.LabelRegionCursor) LabelingType(net.imglib2.roi.labeling.LabelingType) UnsignedShortType(net.imglib2.type.numeric.integer.UnsignedShortType) LabelRegion(net.imglib2.roi.labeling.LabelRegion) CalibratedAxis(net.imagej.axis.CalibratedAxis) LabelRegions(net.imglib2.roi.labeling.LabelRegions) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) Interval(net.imglib2.Interval) IterableInterval(net.imglib2.IterableInterval)

Example 50 with ByteType

use of net.imglib2.type.numeric.integer.ByteType in project imagej-ops by imagej.

the class IntegralCursorTest method testIntegralCursor.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testIntegralCursor() {
    Shape rectangleShape = new RectangleShape(1, false);
    IterableInterval<Neighborhood<ByteType>> ii = rectangleShape.neighborhoodsSafe(img);
    Cursor<Neighborhood<ByteType>> cursor = ii.cursor();
    // Manually select the neighborhood that is centered on the image
    cursor.fwd();
    cursor.fwd();
    cursor.fwd();
    cursor.fwd();
    cursor.fwd();
    IntegralCursor<ByteType> integralCursor = new IntegralCursor<>((RectangleNeighborhood) cursor.get());
    assertEquals(integralCursor.next(), new ByteType((byte) 1));
    assertEquals(integralCursor.next(), new ByteType((byte) 2));
    assertEquals(integralCursor.next(), new ByteType((byte) 5));
    assertEquals(integralCursor.next(), new ByteType((byte) 4));
    assertFalse(integralCursor.hasNext());
    integralCursor.reset();
    assertEquals(integralCursor.next(), new ByteType((byte) 1));
    assertEquals(integralCursor.next(), new ByteType((byte) 2));
    assertEquals(integralCursor.next(), new ByteType((byte) 5));
    assertEquals(integralCursor.next(), new ByteType((byte) 4));
    assertFalse(integralCursor.hasNext());
}
Also used : Shape(net.imglib2.algorithm.neighborhood.Shape) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) ByteType(net.imglib2.type.numeric.integer.ByteType) Neighborhood(net.imglib2.algorithm.neighborhood.Neighborhood) RectangleNeighborhood(net.imglib2.algorithm.neighborhood.RectangleNeighborhood) Test(org.junit.Test)

Aggregations

ByteType (net.imglib2.type.numeric.integer.ByteType)83 Test (org.junit.Test)78 AbstractOpTest (net.imagej.ops.AbstractOpTest)76 RectangleShape (net.imglib2.algorithm.neighborhood.RectangleShape)55 Img (net.imglib2.img.Img)49 ArrayImg (net.imglib2.img.array.ArrayImg)33 Shape (net.imglib2.algorithm.neighborhood.Shape)18 DiamondShape (net.imglib2.algorithm.neighborhood.DiamondShape)17 HorizontalLineShape (net.imglib2.algorithm.neighborhood.HorizontalLineShape)16 ArrayList (java.util.ArrayList)9 Op (net.imagej.ops.Op)9 IterableInterval (net.imglib2.IterableInterval)9 BitType (net.imglib2.type.logic.BitType)6 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)6 AbstractUnaryComputerOp (net.imagej.ops.special.computer.AbstractUnaryComputerOp)5 Ops (net.imagej.ops.Ops)4 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)4 IncompatibleTypeException (net.imglib2.exception.IncompatibleTypeException)4 CreateImgFromImg (net.imagej.ops.create.img.CreateImgFromImg)3 MapOp (net.imagej.ops.map.MapOp)3