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

The following examples show how to use net.imglib2.type.numeric.integer.ShortType. 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: CreateImgTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testCreateFromRaiDifferentType() {
	final IntervalView<ByteType> input =
		Views.interval(PlanarImgs.bytes(10, 10, 10), new FinalInterval(
			new long[] { 10, 10, 1 }));

	final Img<?> res = (Img<?>) ops.run(CreateImgFromDimsAndType.class, input,
		new ShortType());

	assertEquals("Image Type: ", ShortType.class, res.firstElement().getClass());

	assertArrayEquals("Image Dimensions: ", Intervals
		.dimensionsAsLongArray(input), Intervals.dimensionsAsLongArray(res));

	assertEquals("Image Factory: ", ArrayImgFactory.class, res.factory()
		.getClass());
}
 
Example #3
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 #4
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 #5
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 #6
Source File: InvertTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testShortTypeInvert() {
	final Img<ShortType> inShortType = generateShortArrayTestImg(true, 5, 5);
	final Img<ShortType> outShortType = inShortType.factory().create(
		inShortType, new ShortType());
	assertDefaultInvert(inShortType, outShortType);
	assertDefaultInvertMinMaxProvided(inShortType, outShortType, new ShortType(
		(Short.MIN_VALUE)), new ShortType((short) (Short.MIN_VALUE + 1)));
	assertDefaultInvertMinMaxProvided(inShortType, outShortType, new ShortType(
		(Short.MAX_VALUE)), new ShortType((short) (Short.MAX_VALUE - 1)));
	assertDefaultInvertMinMaxProvided(inShortType, outShortType, new ShortType(
		(Short.MAX_VALUE)), new ShortType((Short.MAX_VALUE)));
}
 
Example #7
Source File: CoordinateEquationTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Test the coordinate op version of the equation using 4 dimensions
 */
@Test
public void testEquation4DOp() {

	final long[] size4D = new long[] { 5, 5, 5, 5 };

	final Dimensions dimensions4D = new FinalDimensions(size4D);

	final Img<ShortType> image = ops.create().img(dimensions4D,
		new ShortType());

	// implement c[0]+10*c[1]+100*c[3]+1000*c[4]
	final UnaryFunctionOp<long[], Double> op =
		new AbstractUnaryFunctionOp<long[], Double>()
		{

			@Override
			public Double calculate(final long[] coords) {
				final double result = coords[0] + 10 * coords[1] + 100 * coords[2] +
					1000 * coords[3];

				return result;
			}
		};

	ops.run(DefaultCoordinatesEquation.class, image, op);

	final RandomAccess<ShortType> ra = image.randomAccess();

	ra.setPosition(new long[] { 1, 2, 2, 3 });

	assertEquals(1 + 10 * 2 + 100 * 2 + 1000 * 3, ra.get().getRealFloat(),
		0.000001);

}
 
Example #8
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<ShortType, ShortArray> generateShortArrayTestImg(
	final boolean fill, final long... dims)
{
	final short[] array = new short[(int) Intervals.numElements(
		new FinalInterval(dims))];

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

	return ArrayImgs.shorts(array, dims);
}
 
Example #9
Source File: CreateImgTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testCreateFromImgDifferentType() {
	final Img<ByteType> input = PlanarImgs.bytes(10, 10, 10);
	final Img<?> res = (Img<?>) ops.run(CreateImgFromDimsAndType.class, input,
		new ShortType());

	assertEquals("Image Type: ", ShortType.class, res.firstElement().getClass());
	assertArrayEquals("Image Dimensions: ", Intervals
		.dimensionsAsLongArray(input), Intervals.dimensionsAsLongArray(res));
	assertEquals("Image Factory: ", input.factory().getClass(), res.factory()
		.getClass());
}
 
Example #10
Source File: ConvertIIsTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testNormalizeScale() {
	ops.run(ConvertIIs.class, out, in,
		ops.op(NormalizeScaleRealTypes.class, out.firstElement(), in.firstElement()));

	final Cursor<ShortType> c = in.localizingCursor();
	final RandomAccess<ByteType> ra = out.randomAccess();
	while (c.hasNext()) {
		final short value = c.next().get();
		ra.setPosition(c);
		assertEquals(normalizeScale(value), ra.get().get());
	}
}
 
Example #11
Source File: ConvertIIsTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testScale() {
	ops.run(ConvertIIs.class, out, in,
		new ScaleRealTypes<ShortType, ByteType>());

	final Cursor<ShortType> c = in.localizingCursor();
	final RandomAccess<ByteType> ra = out.randomAccess();
	while (c.hasNext()) {
		final short value = c.next().get();
		ra.setPosition(c);
		assertEquals(scale(value), ra.get().get());
	}
}
 
Example #12
Source File: ConvertIIsTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testCopy() {
	ops.run(ConvertIIs.class, out, in,
		new CopyRealTypes<ShortType, ByteType>());

	final Cursor<ShortType> c = in.localizingCursor();
	final RandomAccess<ByteType> ra = out.randomAccess();
	while (c.hasNext()) {
		final short value = c.next().get();
		ra.setPosition(c);
		assertEquals(copy(value), ra.get().get());
	}
}
 
Example #13
Source File: ConvertIIsTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testClip() {
	ops.run(ConvertIIs.class, out, in,
		new ClipRealTypes<ShortType, ByteType>());

	final Cursor<ShortType> c = in.localizingCursor();
	final RandomAccess<ByteType> ra = out.randomAccess();
	while (c.hasNext()) {
		final short value = c.next().get();
		ra.setPosition(c);
		assertEquals(clip(value), ra.get().get());
	}
}
 
Example #14
Source File: ConvertIIsTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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());
}
 
Example #15
Source File: DefaultCreateIntegerType.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public IntegerType calculate() {
	if (maxValue <= 0L) return new IntType();
	if (maxValue <= 1L) return new BitType();
	if (maxValue <= 0x7fL) return new ByteType();
	if (maxValue <= 0xffL) return new UnsignedByteType();
	if (maxValue <= 0x7fffL) return new ShortType();
	if (maxValue <= 0xffffL) return new UnsignedShortType();
	if (maxValue <= 0x7fffffffL) return new IntType();
	if (maxValue <= 0xffffffffL) return new UnsignedIntType();
	return new LongType();
}
 
Example #16
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.ConvertTypes.IntegerToInt16.class)
public <T extends IntegerType<T>> ShortType int16(final ShortType out,
	final T in)
{
	final ShortType result = (ShortType) ops().run(
		Ops.Convert.Int16.class, out, in);
	return result;
}
 
Example #17
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.ConvertTypes.ComplexToInt16.class)
public <C extends ComplexType<C>> ShortType int16(final ShortType out,
	final C in)
{
	final ShortType result = (ShortType) ops().run(
		Ops.Convert.Int16.class, out, in);
	return result;
}
 
Example #18
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.Int16.class)
public <C extends ComplexType<C>> Img<ShortType> int16(
	final Img<ShortType> out, final IterableInterval<C> in)
{
	@SuppressWarnings("unchecked")
	final Img<ShortType> result = (Img<ShortType>) ops().run(
		Ops.Convert.Int16.class, out, in);
	return result;
}
 
Example #19
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.Int16.class)
public <C extends ComplexType<C>> Img<ShortType> int16(
	final IterableInterval<C> in)
{
	@SuppressWarnings("unchecked")
	final Img<ShortType> result = (Img<ShortType>) ops().run(
		Ops.Convert.Int16.class, in);
	return result;
}
 
Example #20
Source File: ConvertNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@OpMethod(op = net.imagej.ops.convert.ConvertTypes.IntegerToInt16.class)
public <T extends IntegerType<T>> ShortType int16(final T in) {
	final ShortType result = (ShortType) ops().run(
		Ops.Convert.Int16.class, in);
	return result;
}
 
Example #21
Source File: ConvertIIsTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private byte normalizeScale(final short value) {
	Pair<ShortType, ShortType> minMax = ops.stats().minMax(in);
	final double norm = (value - minMax.getA().getRealDouble()) / (minMax.getB()
		.getRealDouble() - minMax.getA().getRealDouble());
	return (byte) Math.round((255 * norm) - 128);
}
 
Example #22
Source File: ConvertIIsTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void addNoise(final Iterable<ShortType> image) {
	// NB: Need "? super ShortType" instead of "?" to make javac happy.
	final UnaryInplaceOp<? super ShortType, ShortType> noiseOp = Inplaces.unary(
		ops, Ops.Filter.AddNoise.class, ShortType.class, -32768, 32767, 10000);
	ops.map(image, noiseOp);
}
 
Example #23
Source File: ConvertNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@OpMethod(op = net.imagej.ops.convert.ConvertTypes.ComplexToInt16.class)
public <C extends ComplexType<C>> ShortType int16(final C in) {
	final ShortType result = (ShortType) ops().run(
		Ops.Convert.Int16.class, in);
	return result;
}
 
Example #24
Source File: CreateIntegerTypeTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Test
public void testInt16() {
	assertType(ShortType.class, 0x7ffeL);
	assertType(ShortType.class, 0x7fffL);
	assertNotType(ShortType.class, 0x8000L);
}
 
Example #25
Source File: ConvertTypes.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final T input, final ShortType output) {
	output.set((short) input.getIntegerLong());
}
 
Example #26
Source File: ConvertTypes.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public ShortType createOutput(final T input) {
	return new ShortType();
}
 
Example #27
Source File: ConvertTypes.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final C input, final ShortType output) {
	output.set((short) input.getRealDouble());
}
 
Example #28
Source File: ConvertTypes.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public ShortType createOutput(final C input) {
	return new ShortType();
}