net.imglib2.type.numeric.integer.IntType Java Examples

The following examples show how to use net.imglib2.type.numeric.integer.IntType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: N5TypesTest.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testType() {
	final Set<DataType> toBeTested = Stream.of(DataType.values()).collect(Collectors.toSet());
	final Set<DataType> wasTested = new HashSet<>();
	testAndLogNativeTypeForType(DataType.FLOAT32, FloatType.class, wasTested);
	testAndLogNativeTypeForType(DataType.FLOAT64, DoubleType.class, wasTested);
	testAndLogNativeTypeForType(DataType.INT8, ByteType.class, wasTested);
	testAndLogNativeTypeForType(DataType.INT16, ShortType.class, wasTested);
	testAndLogNativeTypeForType(DataType.INT32, IntType.class, wasTested);
	testAndLogNativeTypeForType(DataType.INT64, LongType.class, wasTested);
	testAndLogNativeTypeForType(DataType.UINT8, UnsignedByteType.class, wasTested);
	testAndLogNativeTypeForType(DataType.UINT16, UnsignedShortType.class, wasTested);
	testAndLogNativeTypeForType(DataType.UINT32, UnsignedIntType.class, wasTested);
	testAndLogNativeTypeForType(DataType.UINT64, UnsignedLongType.class, wasTested);
	Assert.assertEquals(toBeTested, wasTested);
}
 
Example #2
Source File: ImageNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Executes the "watershedSeeded" operation on the given arguments. */
@OpMethod(op = net.imagej.ops.image.watershed.WatershedSeeded.class)
public <B extends BooleanType<B>, T extends RealType<T>>
	ImgLabeling<Integer, IntType> watershed(
		final ImgLabeling<Integer, IntType> out,
		final RandomAccessibleInterval<T> in,
		final ImgLabeling<Integer, IntType> seeds,
		final boolean eightConnectivity, final boolean drawWatersheds,
		final RandomAccessibleInterval<B> mask)
{
	@SuppressWarnings("unchecked")
	final ImgLabeling<Integer, IntType> result =
		(ImgLabeling<Integer, IntType>) ops().run(
			net.imagej.ops.image.watershed.WatershedSeeded.class, out, in, seeds,
			eightConnectivity, drawWatersheds, mask);
	return result;
}
 
Example #3
Source File: ImageNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@OpMethod(
	op = net.imagej.ops.image.watershed.WatershedBinarySingleSigma.class)
public <T extends BooleanType<T>, B extends BooleanType<B>>
	ImgLabeling<Integer, IntType> watershed(
		final ImgLabeling<Integer, IntType> out,
		final RandomAccessibleInterval<T> in, final boolean useEightConnectivity,
		final boolean drawWatersheds, final double sigma,
		final RandomAccessibleInterval<B> mask)
{
	@SuppressWarnings("unchecked")
	final ImgLabeling<Integer, IntType> result =
		(ImgLabeling<Integer, IntType>) ops().run(
			net.imagej.ops.image.watershed.WatershedBinarySingleSigma.class, out,
			in, useEightConnectivity, drawWatersheds, sigma, mask);
	return result;
}
 
Example #4
Source File: CreateLabelingTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testImageFactory() {

	final Dimensions dim = new FinalDimensions( 10, 10, 10 );

	assertEquals("Labeling Factory: ", ArrayImgFactory.class,
		((Img<?>) ((ImgLabeling<String, ?>) ops.run(
			DefaultCreateImgLabeling.class, dim, null,
			new ArrayImgFactory<IntType>())).getIndexImg()).factory().getClass());

	assertEquals("Labeling Factory: ", CellImgFactory.class,
		((Img<?>) ((ImgLabeling<String, ?>) ops.run(
			DefaultCreateImgLabeling.class, dim, null,
			new CellImgFactory<IntType>())).getIndexImg()).factory().getClass());

}
 
Example #5
Source File: KendallTauBRankTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void exhaustiveKendallTauBRankTesting() {
	assumeTrue(exhaustive);
	final int n = 5, m = 10;
	final int[] values1 = new int[n], values2 = new int[n];
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < n; j++) {
			values1[j] = Math.abs(pseudoRandom()) % m;
			values2[j] = Math.abs(pseudoRandom()) % m;
		}
		
		//final PairIterator<DoubleType> iter = pairIterator(values1, values2);
		final Iterable<Pair<IntType, IntType>> iter = new IterablePair<>(ArrayImgs.ints(values1, n), ArrayImgs.ints(values2, n));
		double kendallValue1 = calculateNaive(iter.iterator());
		double kendallValue2 = (Double) ops.run(KendallTauBRank.class, values1, values2);
		if (Double.isNaN(kendallValue1)) {
			assertTrue("i: " + i + ", value2: " + kendallValue2, Double.isInfinite(kendallValue2) || Double.isNaN(kendallValue2));
		} else {
			assertEquals("i: " + i, kendallValue1, kendallValue2, 1e-10);
		}
	}
}
 
Example #6
Source File: CopyLabelingMappingTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Before
public void createData() {
	@SuppressWarnings("unchecked")
	final ImgLabeling<String, IntType> imgL = (ImgLabeling<String, IntType>) ops
		.run(DefaultCreateImgLabeling.class, new long[] { 10, 10 },
			new IntType());

	final Cursor<LabelingType<String>> inc = imgL.cursor();

	while (inc.hasNext()) {
		inc.next().add(Math.random() > 0.5 ? "A" : "B");
	}

	// and another loop to construct some ABs
	while (inc.hasNext()) {
		inc.next().add(Math.random() > 0.5 ? "A" : "B");
	}

	input = imgL.getMapping();
}
 
Example #7
Source File: CopyImgLabelingTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Before
public void createData() {
	input = (ImgLabeling<String, IntType>) ops.run(
		DefaultCreateImgLabeling.class, new long[] { 10, 10 }, new IntType());

	final Cursor<LabelingType<String>> inc = input.cursor();

	while (inc.hasNext()) {
		inc.next().add(Math.random() > 0.5 ? "A" : "B");
	}

	// and another loop to construct some ABs
	while (inc.hasNext()) {
		inc.next().add(Math.random() > 0.5 ? "A" : "B");
	}

}
 
Example #8
Source File: DefaultImgUtilityService.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Converts ImgLib2 Type object to SCIFIO pixel type.
 */
@Override
public int makeType(final Object type) throws ImgIOException {
	int pixelType = FormatTools.UINT8;
	if (type instanceof UnsignedByteType) {
		pixelType = FormatTools.UINT8;
	}
	else if (type instanceof ByteType) {
		pixelType = FormatTools.INT8;
	}
	else if (type instanceof UnsignedShortType) {
		pixelType = FormatTools.UINT16;
	}
	else if (type instanceof ShortType) {
		pixelType = FormatTools.INT16;
	}
	else if (type instanceof UnsignedIntType) {
		pixelType = FormatTools.UINT32;
	}
	else if (type instanceof IntType) {
		pixelType = FormatTools.INT32;
	}
	else if (type instanceof FloatType) {
		pixelType = FormatTools.FLOAT;
	}
	else if (type instanceof DoubleType) {
		pixelType = FormatTools.DOUBLE;
	}
	else {
		throw new ImgIOException("Pixel type not supported. " +
			"Please convert your image to a supported type.");
	}

	return pixelType;
}
 
Example #9
Source File: DefaultJsonServiceTest.java    From imagej-server with Apache License 2.0 5 votes vote down vote up
@Test
public void serializeSpecialTypes() throws Exception {
	// MixIns and special types are tested together here. Could separate them if
	// needed in the future.
	final LinkedHashMap<String, Object> outputs = new LinkedHashMap<>();
	final IntType intType = new IntType(1);
	final ByteType byteType = new ByteType((byte) 1);
	final ShortType shortType = new ShortType((short) 1);
	final LongType longType = new LongType(1L);
	final FloatType floatType = new FloatType(1.5f);
	final DoubleType doubleType = new DoubleType(1.5d);
	final ComplexDoubleType complexDoubleType = new ComplexDoubleType(1.5, 2.5);
	final Img<ByteType> img0 = Imgs.create(new ArrayImgFactory<>(byteType),
		Intervals.createMinMax(0, 10, 0, 10), byteType);
	final Img<ByteType> img1 = Imgs.create(new PlanarImgFactory<>(byteType),
		Intervals.createMinMax(0, 10, 0, 10), byteType);
	final Foo foo = new Foo("test string");
	outputs.put("intType", intType);
	outputs.put("byteType", byteType);
	outputs.put("shortType", shortType);
	outputs.put("longType", longType);
	outputs.put("floatType", floatType);
	outputs.put("doubleType", doubleType);
	outputs.put("complexDoubleType", complexDoubleType);
	outputs.put("img0", img0);
	outputs.put("img1", img1);
	outputs.put("foo", foo);

	final String normalized = mapper.writeValueAsString(mapper.readValue(
		fixture("fixtures/outputs/specialTypes.json"), Object.class));

	assertEquals(jsonService.parseObject(outputs), normalized);
}
 
Example #10
Source File: N5Types.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param dataType N5 {@link DataType}
 * @param <T> {@link NativeType}
 * @return appropriate {@link NativeType} for {@code dataType}
 */
@SuppressWarnings("unchecked")
public static <T extends NativeType<T>> T type(final DataType dataType) {
	switch (dataType) {
		case INT8:
			return (T) new ByteType();
		case UINT8:
			return (T) new UnsignedByteType();
		case INT16:
			return (T) new ShortType();
		case UINT16:
			return (T) new UnsignedShortType();
		case INT32:
			return (T) new IntType();
		case UINT32:
			return (T) new UnsignedIntType();
		case INT64:
			return (T) new LongType();
		case UINT64:
			return (T) new UnsignedLongType();
		case FLOAT32:
			return (T) new FloatType();
		case FLOAT64:
			return (T) new DoubleType();
		default:
			return null;
	}
}
 
Example #11
Source File: WatershedBinary.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example #12
Source File: WatershedBinarySingleSigma.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example #13
Source File: AbstractFeatureTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected static <T extends RealType<T>> LabelRegion<String> createLabelRegion(
	final RandomAccessibleInterval<T> interval, final float min, final float max, long... dims)
{
	if (dims == null || dims.length == 0) {
		dims = new long[interval.numDimensions()];
		interval.dimensions(dims);
	}
	final ImgLabeling<String, IntType> labeling = 
		new ImgLabeling<>(ArrayImgs.ints(dims));

	final RandomAccess<LabelingType<String>> ra = labeling.randomAccess();
	final RandomAccessibleIntervalCursor<T> c = new RandomAccessibleIntervalCursor<>(interval);		
	final long[] pos = new long[labeling.numDimensions()];
	while (c.hasNext()) {
		final T item = c.next();
		final float value = item.getRealFloat();
		if (value >= min && value <= max) {
			c.localize(pos);
			ra.setPosition(pos);
			ra.get().add("1");
		}
	}
	final LabelRegions<String> labelRegions = new LabelRegions<>(labeling);

	return labelRegions.getLabelRegion("1");

}
 
Example #14
Source File: CreateImgTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testImageType() {
	final Dimensions dim = new FinalDimensions(10, 10, 10);

	assertEquals("Image Type: ", BitType.class, ((Img<?>) ops.run(
		CreateImgFromDimsAndType.class, dim, new BitType())).firstElement()
			.getClass());

	assertEquals("Image Type: ", ByteType.class, ((Img<?>) ops.run(
		CreateImgFromDimsAndType.class, dim, new ByteType())).firstElement()
			.getClass());

	assertEquals("Image Type: ", UnsignedByteType.class, ((Img<?>) ops.create()
		.img(dim, new UnsignedByteType())).firstElement().getClass());

	assertEquals("Image Type: ", IntType.class, ((Img<?>) ops.run(
		CreateImgFromDimsAndType.class, dim, new IntType())).firstElement()
			.getClass());

	assertEquals("Image Type: ", FloatType.class, ((Img<?>) ops.run(
		CreateImgFromDimsAndType.class, dim, new FloatType())).firstElement()
			.getClass());

	assertEquals("Image Type: ", DoubleType.class, ((Img<?>) ops.run(
		CreateImgFromDimsAndType.class, dim, new DoubleType())).firstElement()
			.getClass());
}
 
Example #15
Source File: AVIWriterTest.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testWriting_uint8() throws IOException {

	final ImgPlus<IntType> sourceImg = (ImgPlus<IntType>) opener.openImgs(
		new TestImgLocation.Builder().name("8bit-unsigned").pixelType("uint8")
			.axes("X", "Y", "Channel", "Time").lengths(100, 100, 3, 5).build()).get(0);
	testWriting(sourceImg);
}
 
Example #16
Source File: QTWriterTest.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testWriting_uint8() throws IOException {

	final ImgPlus<IntType> sourceImg = (ImgPlus<IntType>) opener.openImgs(
		new TestImgLocation.Builder().name("8bit-unsigned").pixelType("uint8")
			.axes("X", "Y", "Channel", "Time").lengths(100, 100, 3, 30).build()).get(0);
	testWriting(sourceImg);
}
 
Example #17
Source File: WatershedTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void testWithoutMask(final RandomAccessibleInterval<FloatType> in) {
	// create mask which is 1 everywhere
	long[] dims = new long[in.numDimensions()];
	in.dimensions(dims);
	Img<BitType> mask = ArrayImgs.bits(dims);
	for (BitType b : mask) {
		b.setOne();
	}

	/*
	 * use 8-connected neighborhood
	 */
	// compute result without watersheds
	ImgLabeling<Integer, IntType> out = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, in, true,
			false);

	assertResults(in, out, mask, true, false, false);

	// compute result with watersheds
	ImgLabeling<Integer, IntType> out2 = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, in, true,
			true);

	assertResults(in, out2, mask, true, true, false);

	/*
	 * use 4-connected neighborhood
	 */
	// compute result without watersheds
	ImgLabeling<Integer, IntType> out3 = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, in, false,
			false);

	assertResults(in, out3, mask, false, false, false);

	// compute result with watersheds
	ImgLabeling<Integer, IntType> out4 = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, in, false,
			true);

	assertResults(in, out4, mask, false, true, false);
}
 
Example #18
Source File: WatershedTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void assertResults(final RandomAccessibleInterval<FloatType> in, final ImgLabeling<Integer, IntType> out,
		final RandomAccessibleInterval<BitType> mask, final boolean useEighConnect, final boolean withWatersheds,
		final boolean smallMask) {

	final Cursor<LabelingType<Integer>> curOut = out.cursor();
	final RandomAccess<BitType> raMask = mask.randomAccess();
	while (curOut.hasNext()) {
		curOut.fwd();
		raMask.setPosition(curOut);
		if (raMask.get().get()) {
			assertEquals(true, curOut.get().size() == 0 || curOut.get().size() == 1);
		} else {
			assertEquals(true, curOut.get().isEmpty());
		}
	}
	// Sample the output image based on the mask
	IterableRegion<BitType> regions = Regions.iterable(mask);

	// count labels
	Set<Integer> labelSet = new HashSet<>();
	for (LabelingType<Integer> pixel : Regions.sample(regions, out)) {
		labelSet.addAll(pixel);
	}

	// assert equals
	assertEquals(in.numDimensions(), out.numDimensions());
	assertEquals(in.dimension(0), out.dimension(0));
	assertEquals(in.dimension(1), out.dimension(1));
	if (smallMask) {
		assertEquals(3 + (withWatersheds ? 1 : 0), labelSet.size());
	} else {
		assertEquals(10 + (withWatersheds ? 1 : 0), labelSet.size());
	}
}
 
Example #19
Source File: CopyImgLabelingTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void copyImgLabeling() {
	ImgLabeling<String, IntType> copy = (ImgLabeling<String, IntType>) ops
			.run(CopyImgLabeling.class, input);
	assertNotNull(copy);

	Cursor<LabelingType<String>> inCursor = input.cursor();
	for (final LabelingType<String> type : copy) {
		assertEquals(inCursor.next(), type);
	}
}
 
Example #20
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<IntType, IntArray> generateIntArrayTestImg(final boolean fill,
	final long... dims)
{
	final int[] array = new int[(int) Intervals.numElements(new FinalInterval(
		dims))];

	if (fill) {
		seed = 17;
		for (int i = 0; i < array.length; i++) {
			array[i] = (int) pseudoRandom() / (int) Integer.MAX_VALUE;
		}
	}

	return ArrayImgs.ints(array, dims);
}
 
Example #21
Source File: InvertTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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));
}
 
Example #22
Source File: WatershedBinarySingleSigmaTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void assertResults(final ImgLabeling<Integer, IntType> expOut, final ImgLabeling<Integer, IntType> out) {
	Cursor<LabelingType<Integer>> expOutCursor = expOut.cursor();
	RandomAccess<LabelingType<Integer>> raOut = out.randomAccess();

	while (expOutCursor.hasNext()) {
		expOutCursor.fwd();
		raOut.setPosition(expOutCursor);
		assertEquals(expOutCursor.get().size(), raOut.get().size());
		if (expOutCursor.get().size() > 0)
			assertEquals(expOutCursor.get().iterator().next(), raOut.get().iterator().next());
	}

}
 
Example #23
Source File: WatershedBinaryTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void assertResults(final ImgLabeling<Integer, IntType> expOut, final ImgLabeling<Integer, IntType> out) {
	Cursor<LabelingType<Integer>> expOutCursor = expOut.cursor();
	RandomAccess<LabelingType<Integer>> raOut = out.randomAccess();

	while (expOutCursor.hasNext()) {
		expOutCursor.fwd();
		raOut.setPosition(expOutCursor);
		assertEquals(expOutCursor.get().size(), raOut.get().size());
		if (expOutCursor.get().size() > 0)
			assertEquals(expOutCursor.get().iterator().next(), raOut.get().iterator().next());
	}

}
 
Example #24
Source File: WatershedSeededTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void test() {
	long[] dims = { 15, 30 };
	// create input image
	Img<FloatType> input = ArrayImgs.floats(dims);
	MersenneTwisterFast random = new MersenneTwisterFast(SEED);
	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);
}
 
Example #25
Source File: WatershedSeededTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void assertResults(final RandomAccessibleInterval<FloatType> in, final ImgLabeling<Integer, IntType> out,
		final ImgLabeling<Integer, IntType> seeds, final RandomAccessibleInterval<BitType> mask,
		final boolean withWatersheds, final boolean smallMask) {

	final Cursor<LabelingType<Integer>> curOut = out.cursor();
	final RandomAccess<BitType> raMask = mask.randomAccess();
	while (curOut.hasNext()) {
		curOut.fwd();
		raMask.setPosition(curOut);
		if (raMask.get().get()) {
			assertEquals(1, curOut.get().size());
		} else {
			assertEquals(true, curOut.get().isEmpty());
		}
	}
	// Sample the output image based on the mask
	IterableRegion<BitType> regions = Regions.iterable(mask);

	// count labels
	Set<Integer> labelSet = new HashSet<>();
	for (LabelingType<Integer> pixel : Regions.sample(regions, out)) {
		labelSet.addAll(pixel);
	}

	// assert equals
	assertEquals(in.numDimensions(), out.numDimensions());
	assertEquals(in.dimension(0), out.dimension(0));
	assertEquals(in.dimension(1), out.dimension(1));
	assertEquals(3 + (withWatersheds ? 1 : 0), labelSet.size() + (smallMask ? 1 : 0));
}
 
Example #26
Source File: ImageNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Executes the "watershedSeeded" operation on the given arguments. */
@OpMethod(op = net.imagej.ops.image.watershed.WatershedSeeded.class)
public <T extends RealType<T>> ImgLabeling<Integer, IntType> watershed(
	final RandomAccessibleInterval<T> in,
	final ImgLabeling<Integer, IntType> seeds, final boolean eightConnectivity,
	final boolean drawWatersheds)
{
	@SuppressWarnings("unchecked")
	final ImgLabeling<Integer, IntType> result =
		((ImgLabeling<Integer, IntType>) ops().run(
			net.imagej.ops.image.watershed.WatershedSeeded.class, in, seeds,
			eightConnectivity, drawWatersheds));
	return result;
}
 
Example #27
Source File: AddLabelImage.java    From sciview with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void run() {

    // interpret the current image as a label image and convert it to ImgLabeling

    @SuppressWarnings("unchecked")
    Img<T> labelMap = ( Img<T> ) currentImage.getImgPlus();

    final Dimensions dims = labelMap;
    final IntType t = new IntType();
    final RandomAccessibleInterval<IntType> img = Util.getArrayOrCellImgFactory( dims, t ).create( dims, t );
    ImgLabeling<Integer, IntType> labeling = new ImgLabeling<>( img );

    final Cursor<LabelingType<Integer>> labelCursor = Views.flatIterable( labeling ).cursor();

    for( final T input : Views.flatIterable( labelMap ) ) {
        final LabelingType<Integer> element = labelCursor.next();
        if( input.getRealFloat() != 0 ) {
            element.add( ( int ) input.getRealFloat() );
        }
    }

    // take the regions, process them to meshes and put it in the viewer
    LabelRegions<Integer> labelRegions = new LabelRegions<>( labeling );

    Object[] regionsArr = labelRegions.getExistingLabels().toArray();
    for( int i = 0; i < labelRegions.getExistingLabels().size(); i++ ) {
        LabelRegion<Integer> lr = labelRegions.getLabelRegion( ( Integer ) regionsArr[i] );

        Mesh mesh = ops.geom().marchingCubes( lr );
        sciView.addMesh( mesh );
    }
}
 
Example #28
Source File: ShowSegmentationDemo.java    From sciview with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void run() {
    sciView.getFloor().setVisible(false);

    RandomAccessibleInterval<UnsignedByteType> inputImage = generateDemo(100, 100, 100, numSegments);

    Volume v = (Volume) sciView.addVolume( inputImage, new float[] { 1, 1, 1 } );
    v.setPixelToWorldRatio(0.05f);
    v.setName( "Segmentation Viz Demo" );
    v.setNeedsUpdate(true);

    ImgLabeling<Integer, IntType> labeling = ops.labeling().cca(inputImage, ConnectedComponents.StructuringElement.FOUR_CONNECTED);
    LabelRegions<Integer> regions = new LabelRegions<>(labeling);

    for( LabelRegion region : regions ) {
        // Generate the mesh with imagej-ops
        Mesh m = ops.geom().marchingCubes( region, 1, new BitTypeVertexInterpolator() );

        // Convert the mesh into a scenery mesh for visualization
        graphics.scenery.Mesh isoSurfaceMesh = MeshConverter.toScenery(m,false);

        // Name the mesh after the segment label
        isoSurfaceMesh.setName( "region " + region );

        // Make a random color and assign it
        Vector3f c = new Vector3f(rng.nextFloat(), rng.nextFloat(), rng.nextFloat());
        isoSurfaceMesh.getMaterial().setDiffuse(c);
        isoSurfaceMesh.getMaterial().setAmbient(c);
        isoSurfaceMesh.getMaterial().setSpecular(c);

        // Make the segmentation mesh a child of the parent
        v.addChild(isoSurfaceMesh);
    }

    sciView.centerOnNode(v);
}
 
Example #29
Source File: ConvertNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(op = net.imagej.ops.convert.ConvertImages.Int32.class)
public <C extends ComplexType<C>> Img<IntType> int32(
	final IterableInterval<C> in)
{
	@SuppressWarnings("unchecked")
	final Img<IntType> result = (Img<IntType>) ops().run(
		Ops.Convert.Int32.class, in);
	return result;
}
 
Example #30
Source File: ConvertNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(op = net.imagej.ops.convert.ConvertImages.Int32.class)
public <C extends ComplexType<C>> Img<IntType> int32(final Img<IntType> out,
	final IterableInterval<C> in)
{
	@SuppressWarnings("unchecked")
	final Img<IntType> result = (Img<IntType>) ops().run(
		Ops.Convert.Int32.class, out, in);
	return result;
}