use of net.imglib2.type.numeric.integer.IntType in project imagej-ops by imagej.
the class WatershedBinarySingleSigma method compute.
@Override
public void compute(final RandomAccessibleInterval<T> in, final ImgLabeling<Integer, IntType> out) {
// compute distance transform
final RandomAccessibleInterval<FloatType> distMap = ops().image().distancetransform(in);
final RandomAccessibleInterval<FloatType> invertedDT = ops().create().img(in, new FloatType());
ops().image().invert(Views.iterable(invertedDT), Views.iterable(distMap));
final RandomAccessibleInterval<FloatType> gauss = ops().filter().gauss(invertedDT, sigma);
// run the default watershed
ops().run(Watershed.class, out, gauss, useEightConnectivity, drawWatersheds, mask);
}
use of net.imglib2.type.numeric.integer.IntType in project imagej-ops by imagej.
the class InvertTest method testIntTypeInvert.
@Test
public void testIntTypeInvert() {
final Img<IntType> inIntType = generateIntArrayTestImg(true, 5, 5);
final Img<IntType> outIntType = inIntType.factory().create(inIntType, new IntType());
assertDefaultInvert(inIntType, outIntType);
assertDefaultInvertMinMaxProvided(inIntType, outIntType, new IntType(10), new IntType(40));
assertDefaultInvertMinMaxProvided(inIntType, outIntType, new IntType(Integer.MIN_VALUE), new IntType(-10));
}
use of net.imglib2.type.numeric.integer.IntType in project imagej-ops by imagej.
the class WatershedBinaryTest method test.
@SuppressWarnings("unchecked")
@Test
public void test() {
// load test image
Img<FloatType> watershedTestImg = openFloatImg(WatershedTest.class, "watershed_test_image.png");
// threshold it
RandomAccessibleInterval<BitType> thresholdedImg = ops.create().img(watershedTestImg, new BitType());
ops.threshold().apply(Views.flatIterable(thresholdedImg), Views.flatIterable(watershedTestImg), new FloatType(1));
// compute inverted distance transform and smooth it with gaussian
// filtering
final RandomAccessibleInterval<FloatType> distMap = ops.image().distancetransform(thresholdedImg);
final RandomAccessibleInterval<FloatType> invertedDistMap = ops.create().img(distMap, new FloatType());
ops.image().invert(Views.iterable(invertedDistMap), Views.iterable(distMap));
double[] sigma = { 3.0, 3.0, 0.0 };
final RandomAccessibleInterval<FloatType> gauss = ops.filter().gauss(invertedDistMap, sigma[0], sigma[1]);
// run randomly only one configuration to save execution time
int nextInt = new Random().nextInt(3);
if (nextInt == 0) {
// compute result
final ImgLabeling<Integer, IntType> out1 = (ImgLabeling<Integer, IntType>) ops.run(WatershedBinary.class, null, thresholdedImg, true, false, sigma, thresholdedImg);
final ImgLabeling<Integer, IntType> expOut1 = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, gauss, true, false, thresholdedImg);
assertResults(expOut1, out1);
final ImgLabeling<Integer, IntType> out2 = (ImgLabeling<Integer, IntType>) ops.run(WatershedBinary.class, null, thresholdedImg, true, false, sigma);
final ImgLabeling<Integer, IntType> expOut2 = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, gauss, true, false);
assertResults(expOut2, out2);
} else if (nextInt == 1) {
// compute result
final ImgLabeling<Integer, IntType> out1 = (ImgLabeling<Integer, IntType>) ops.run(WatershedBinary.class, null, thresholdedImg, true, true, sigma, thresholdedImg);
final ImgLabeling<Integer, IntType> expOut1 = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, gauss, true, true, thresholdedImg);
assertResults(expOut1, out1);
final ImgLabeling<Integer, IntType> out2 = (ImgLabeling<Integer, IntType>) ops.run(WatershedBinary.class, null, thresholdedImg, true, true, sigma);
final ImgLabeling<Integer, IntType> expOut2 = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, gauss, true, true);
assertResults(expOut2, out2);
} else {
// compute result
final ImgLabeling<Integer, IntType> out1 = (ImgLabeling<Integer, IntType>) ops.run(WatershedBinary.class, null, thresholdedImg, false, true, sigma, thresholdedImg);
final ImgLabeling<Integer, IntType> expOut1 = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, gauss, false, true, thresholdedImg);
assertResults(expOut1, out1);
final ImgLabeling<Integer, IntType> out2 = (ImgLabeling<Integer, IntType>) ops.run(WatershedBinary.class, null, thresholdedImg, false, true, sigma);
final ImgLabeling<Integer, IntType> expOut2 = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, gauss, false, true);
assertResults(expOut2, out2);
}
}
use of net.imglib2.type.numeric.integer.IntType in project imagej-ops by imagej.
the class WatershedSeededTest method testWithMask.
@SuppressWarnings("unchecked")
private void testWithMask(final RandomAccessibleInterval<FloatType> in, final ImgLabeling<Integer, IntType> seeds) {
// create mask which is 1 everywhere
long[] dims = new long[in.numDimensions()];
in.dimensions(dims);
Img<BitType> mask = ArrayImgs.bits(dims);
RandomAccess<BitType> raMask = mask.randomAccess();
for (BitType b : mask) {
b.setZero();
}
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++) {
raMask.setPosition(new int[] { x, y });
raMask.get().setOne();
}
}
/*
* use 8-connected neighborhood
*/
// compute result without watersheds
ImgLabeling<Integer, IntType> out = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, true, false, mask);
assertResults(in, out, seeds, mask, false, true);
// compute result with watersheds
ImgLabeling<Integer, IntType> out2 = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, true, true, mask);
assertResults(in, out2, seeds, mask, true, true);
/*
* use 4-connected neighborhood
*/
// compute result without watersheds
ImgLabeling<Integer, IntType> out3 = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, false, false, mask);
assertResults(in, out3, seeds, mask, false, true);
// compute result with watersheds
ImgLabeling<Integer, IntType> out4 = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, false, true, mask);
assertResults(in, out4, seeds, mask, true, true);
}
use of net.imglib2.type.numeric.integer.IntType in project imagej-ops by imagej.
the class WatershedSeededTest method test.
@Test
public void test() {
long[] dims = { 15, 30 };
// create input image
Img<FloatType> input = ArrayImgs.floats(dims);
Random random = new Random();
for (FloatType b : input) {
b.setReal(random.nextDouble());
}
// create 3 seeds
Img<BitType> bits = ArrayImgs.bits(dims);
RandomAccess<BitType> ra = bits.randomAccess();
ra.setPosition(new int[] { 0, 0 });
ra.get().set(true);
ra.setPosition(new int[] { 4, 6 });
ra.get().set(true);
ra.setPosition(new int[] { 10, 20 });
ra.get().set(true);
// compute labeled seeds
final ImgLabeling<Integer, IntType> labeledSeeds = ops.labeling().cca(bits, StructuringElement.EIGHT_CONNECTED);
testWithoutMask(input, labeledSeeds);
testWithMask(input, labeledSeeds);
}
Aggregations