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

The following examples show how to use net.imglib2.type.numeric.integer.UnsignedByteType. 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: AbstractFeatureTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * @param dim a long array with the desired dimensions of the image
 * @param constValue constant image value
 * @return an {@link Img} of {@link UnsignedByteType} filled with a constant
 *         value.
 */
public Img<UnsignedByteType> getConstantUnsignedByteImg(final long[] dim,
	final int constValue)
{
	final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(
		dim);

	final UnsignedByteType type = img.firstElement();
	if (constValue < type.getMinValue() || constValue >= type.getMaxValue()) {
		throw new IllegalArgumentException("Can't create image for constant [" +
			constValue + "]");
	}

	final ArrayCursor<UnsignedByteType> cursor = img.cursor();
	while (cursor.hasNext()) {
		cursor.next().set(constValue);
	}

	return img;
}
 
Example #2
Source File: Utils.java    From sciview with BSD 2-Clause "Simplified" License 6 votes vote down vote up
static public Img<ARGBType> convertToARGB(Img<UnsignedByteType> screenshot) {
    Img<ARGBType> out = ArrayImgs.argbs(screenshot.dimension(0), screenshot.dimension(1));
    long[] pos = new long[3];
    Cursor<ARGBType> outCur = Views.iterable(out).cursor();
    RandomAccess<UnsignedByteType> sRA = screenshot.randomAccess();
    while( outCur.hasNext() ) {
        outCur.fwd();
        outCur.localize(pos);

        pos[2] = 0;
        sRA.setPosition(pos);
        int r = sRA.get().get();
        pos[2] = 1;
        sRA.setPosition(pos);
        int g = sRA.get().get();
        pos[2] = 2;
        sRA.setPosition(pos);
        int b = sRA.get().get();

        int a = 255;// FIXME

        outCur.get().set(ARGBType.rgba(r, g, b, a));
    }
    return out;
}
 
Example #3
Source File: SciView.java    From sciview with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Take a screenshot and return it as an Img
 * @return an Img of type UnsignedByteType
 */
public Img<UnsignedByteType> getScreenshot() {
    RenderedImage screenshot = getSceneryRenderer().requestScreenshot();

    BufferedImage image = new BufferedImage(screenshot.getWidth(), screenshot.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
    byte[] imgData = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    System.arraycopy(screenshot.getData(), 0, imgData, 0, screenshot.getData().length);

    Img<UnsignedByteType> img = null;
    File tmpFile = null;
    try {
        tmpFile = File.createTempFile("sciview-", "-tmp.png");
        ImageIO.write(image, "png", tmpFile);
        img = (Img<UnsignedByteType>)io.open(tmpFile.getAbsolutePath());
        tmpFile.delete();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return img;
}
 
Example #4
Source File: ImagePlaneDemo.java    From sciview with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static ByteBuffer imgToByteBuffer(Img<UnsignedByteType> img) {
    int numBytes = (int) (img.dimension(0) * img.dimension(1) * 3);
    ByteBuffer bb = BufferUtils.allocateByte(numBytes);
    byte[] rgb = new byte[]{0, 0, 0};

    RandomAccess<UnsignedByteType> ra = img.randomAccess();

    long[] pos = new long[3];

    for( int y = 0; y < img.dimension(1); y++ ) {
        for( int x = 0; x < img.dimension(0); x++ ) {
            for( int c = 0; c < img.dimension(2) - 1; c++ ) {// hard coded dropping of alpha
                pos[0] = x; pos[1] = img.dimension(1) - y - 1; pos[2] = c;
                ra.setPosition(pos);
                rgb[c] = ra.get().getByte();
            }
            bb.put(rgb);
        }
    }
    bb.flip();

    return bb;
}
 
Example #5
Source File: CopyRAITest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void copyRAIDifferentSizeTest() {

	// create a copy op
	final UnaryHybridCF<IntervalView<UnsignedByteType>, RandomAccessibleInterval<UnsignedByteType>> copy =
		(UnaryHybridCF) Hybrids.unaryCF(ops, CopyRAI.class,
			RandomAccessibleInterval.class, IntervalView.class);

	assertNotNull(copy);

	final Img<UnsignedByteType> out = ops.create().img(new FinalDimensions(
		size2), new UnsignedByteType());

	// copy view to output and assert that is equal to the mean of the view
	copy.compute(view, out);
	assertEquals(ops.stats().mean(out).getRealDouble(), 100.0, delta);

	// also try with a planar image
	final Img<UnsignedByteType> outFromPlanar = ops.create().img(
		new FinalDimensions(size2), new UnsignedByteType());

	copy.compute(viewPlanar, outFromPlanar);
	assertEquals(ops.stats().mean(outFromPlanar).getRealDouble(), 100.0, delta);

}
 
Example #6
Source File: ShuffledViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testSameSeed() {
	// FIRST - create 6x6 image filled with known values
	ArrayImg<UnsignedByteType, ByteArray> inputImage = ArrayImgs.unsignedBytes(
		new byte[] { //
			1, 2, 3, 4, 5, 6, //
			7, 8, 9, 10, 11, 12, //
			13, 14, 15, 16, 17, 18, //
			19, 20, 21, 22, 23, 24, //
			25, 26, 27, 28, 29, 30, //
			31, 32, 33, 34, 35, 36 //
		}, 6, 6);
	int[] blockSize = { 2, 2 };
	long seed = 0xdeadbeef;
	ShuffledView<UnsignedByteType> shuffled01 = new ShuffledView<>(inputImage,
		blockSize, seed);
	ShuffledView<UnsignedByteType> shuffled02 = new ShuffledView<>(inputImage,
		blockSize, seed);
	assertIterationsEqual(Views.iterable(shuffled01), Views.iterable(
		shuffled02));
}
 
Example #7
Source File: MTKTTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testMTKTpValueImage() {
	RandomAccessibleInterval<UnsignedByteType> cropCh1 = Views.interval(
		zeroCorrelationImageCh1, new long[] { 0, 0, 0 }, new long[] { 20, 20, 0 });
	RandomAccessibleInterval<UnsignedByteType> cropCh2 = Views.interval(
		zeroCorrelationImageCh2, new long[] { 0, 0, 0 }, new long[] { 20, 20, 0 });
	BinaryFunctionOp<RandomAccessibleInterval<UnsignedByteType>, RandomAccessibleInterval<UnsignedByteType>, Double> op =
		Functions.binary(ops, MTKT.class, Double.class, cropCh1, cropCh2);
	final int[] blockSize = new int[cropCh1.numDimensions()];
	for (int d = 0; d < blockSize.length; d++) {
		final long size = (long) Math.floor(Math.sqrt(cropCh1
			.dimension(d)));
		blockSize[d] = (int) size;
	}
	RandomAccessibleInterval<UnsignedByteType> ch1 = ShuffledView.cropAtMin(
		cropCh1, blockSize);
	RandomAccessibleInterval<UnsignedByteType> ch2 = ShuffledView.cropAtMin(
		cropCh2, blockSize);
	PValueResult value = (PValueResult) ops.run(Ops.Coloc.PValue.class,
		new PValueResult(), ch1, ch2, op, 5);
	assertEquals(0.2, value.getPValue(), 0.0);
}
 
Example #8
Source File: MeshTextureDemo.java    From sciview with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static Texture generateTexture() {
    int width = 64;
    int height = 128;

    Vector3i dims = new Vector3i( width, height, 1 );
    int nChannels = 1;

    ByteBuffer bb = BufferUtils.Companion.allocateByte( width * height * nChannels );

    for( int x = 0; x < width; x++ ) {
        for( int y = 0; y < height; y++ ) {
            bb.put( ( byte ) ( Math.random() * 255 ) );
        }
    }
    bb.flip();

    return new Texture( dims,
nChannels,
new UnsignedByteType(),
bb,
new Triple(Texture.RepeatMode.Repeat,
    Texture.RepeatMode.Repeat,
    Texture.RepeatMode.ClampToEdge));
}
 
Example #9
Source File: VolumeTimeseriesDemo.java    From sciview with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Img<UnsignedByteType> hardCopy(RandomAccessibleInterval<UnsignedByteType> img) {
    Img<UnsignedByteType> out =
            ArrayImgs.unsignedBytes(
                    img.dimension(0),
                    img.dimension(1),
                    img.dimension(2),
                    img.dimension(3));
    RandomAccess<UnsignedByteType> imgAccess = img.randomAccess();

    Cursor<UnsignedByteType> outCur = out.localizingCursor();
    while( outCur.hasNext() ) {
        outCur.fwd();
        imgAccess.setPosition(outCur);
        outCur.get().set(imgAccess.get());
    }

    return out;
}
 
Example #10
Source File: BDVSlicingDemo.java    From sciview with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void run() {
    final Dataset cube;
    try {
        File cubeFile = ResourceLoader.createFile( getClass(), "/cored_cube_var2_8bit.tif" );

        cube = datasetIO.open( cubeFile.getAbsolutePath() );
    }
    catch (IOException exc) {
        log.error( exc );
        return;
    }

    Volume v = (Volume) sciView.addVolume( cube, new float[] { 1, 1, 1 } );
    v.setPixelToWorldRatio(0.1f);// FIXME
    v.setName( "Volume Render Demo" );
    v.setDirty(true);
    v.setNeedsUpdate(true);

    List<SourceAndConverter<UnsignedByteType>> sources = (List<SourceAndConverter<UnsignedByteType>>) v.getMetadata().get("sources");

    BdvFunctions.show(sources.get(0).getSpimSource(), new BdvOptions().frameTitle("slice of " + v.getName()));

    sciView.setActiveNode(v);
    sciView.centerOnNode( sciView.getActiveNode() );
}
 
Example #11
Source File: MaskAndRoiTest.java    From Colocalisation_Analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests a PredicateCursor by checking if all visited values are "true".
 * @throws MissingPreconditionException
 */
@Test
public void predicateCursorTest() throws MissingPreconditionException {
	// load a 3D test image
	RandomAccessibleInterval<UnsignedByteType> img = positiveCorrelationImageCh1;
	long[] roiOffset = createRoiOffset(img);
	long[] roiSize = createRoiSize(img);
	long[] dim = new long[ img.numDimensions() ];
	img.dimensions(dim);
	RandomAccessibleInterval<BitType> mask = MaskFactory.createMask(dim,
			roiOffset, roiSize);

	// create cursor to walk an image with respect to a mask
	final Predicate<BitType> predicate = new MaskPredicate();
	Cursor<BitType> roiCursor
		= new PredicateCursor<BitType>(
				Views.iterable(mask).localizingCursor(), predicate);

	// test if all visited voxels are "true"
	while (roiCursor.hasNext()) {
		roiCursor.fwd();
		assertTrue(roiCursor.get().get());
	}
}
 
Example #12
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 #13
Source File: ProjectTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Before
public void initImg() {
	in = generateUnsignedByteArrayTestImg(false, 10, 10, 10);

	final RandomAccess<UnsignedByteType> randomAccess = in.randomAccess();

	// at each x,y,z fill with x+y
	for (int x = 0; x < 10; x++) {
		for (int y = 0; y < 10; y++) {
			for (int z = 0; z < 10; z++) {
				randomAccess.setPosition(new long[] { x, y, z });
				randomAccess.get().setReal(x + y);
			}
		}
	}

	out1 = generateUnsignedByteArrayTestImg(false, 10, 10);
	out2 = generateUnsignedByteArrayTestImg(false, 10, 10);

	op = Computers.unary(ops, Ops.Stats.Sum.class, UnsignedByteType.class,
		out1);
}
 
Example #14
Source File: ASCIITest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testDefaultASCII() {
	// character set used in DefaultASCII, could be updated if necessary
	final String CHARS = "#O*o+-,. ";
	final int len = CHARS.length();
	final int width = 10;
	final int offset = 47;
	final byte[] array = new byte[width * len];
	for (int i = 0; i < len; i++) {
		for (int j = 0; j < width; j++) {
			array[i * width + j] = (byte) (offset + i * width + j);
		}
	}
	final Img<UnsignedByteType> img = ArrayImgs.unsignedBytes(array, width,
		len);
	final String ascii = (String) ops.run(DefaultASCII.class, img);
	for (int i = 0; i < len; i++) {
		for (int j = 0; j < width; j++) {
			assertTrue(ascii.charAt(i * (width + 1) + j) == CHARS.charAt(i));
		}
		assertTrue(ascii.charAt(i * (width + 1) + width) == '\n');
	}
}
 
Example #15
Source File: ProjectTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void testEquality(final Img<UnsignedByteType> img1,
	final Img<UnsignedByteType> img2)
{
	final RandomAccess<UnsignedByteType> img1RandomAccess = img1.randomAccess();
	final RandomAccess<UnsignedByteType> img2RandomAccess = img2.randomAccess();

	// at each x,y position the sum projection should be (x+y) *size(z)
	for (int x = 0; x < 10; x++) {
		for (int y = 0; y < 10; y++) {
			img1RandomAccess.setPosition(new long[] { x, y });
			img2RandomAccess.setPosition(new long[] { x, y });

			assertEquals(img1RandomAccess.get().get(), //
				in.dimension(PROJECTION_DIM) * (x + y));
			assertEquals(img2RandomAccess.get().get(), //
				in.dimension(PROJECTION_DIM) * (x + y));
		}
	}
}
 
Example #16
Source File: EPSWriterTest.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<UnsignedByteType> sourceImg = (ImgPlus<UnsignedByteType>) opener
		.openImgs(new TestImgLocation.Builder().name("8bit-unsigned").pixelType(
			"uint8").axes("X", "Y", "Channel").lengths(100, 100, 3).build()).get(0);
	testWriting(sourceImg);
}
 
Example #17
Source File: InvertTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testUnsignedByteTypeInvert() {
	final Img<UnsignedByteType> inUnsignedByteType =
		generateUnsignedByteArrayTestImg(true, 5, 5);
	final Img<UnsignedByteType> outUnsignedByteType = inUnsignedByteType
		.factory().create(inUnsignedByteType, new UnsignedByteType());
	assertDefaultInvert(inUnsignedByteType, outUnsignedByteType);
	assertDefaultInvertMinMaxProvided(inUnsignedByteType, outUnsignedByteType,
		new UnsignedByteType((byte) 127), new UnsignedByteType((byte) 127));
	assertDefaultInvertMinMaxProvided(inUnsignedByteType, outUnsignedByteType,
		new UnsignedByteType((byte) -12), new UnsignedByteType((byte) -10));
}
 
Example #18
Source File: SpearmanRankTest.java    From Colocalisation_Analysis with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks Spearman's Rank Correlation value for zero correlated images. The rho value
 * should be about zero.
 */
@Test
public void spearmanZeroCorrTest() throws MissingPreconditionException {
	TwinCursor<UnsignedByteType> cursor = new TwinCursor<UnsignedByteType>(
			zeroCorrelationImageCh1.randomAccess(),
			zeroCorrelationImageCh2.randomAccess(),
			Views.iterable(zeroCorrelationAlwaysTrueMask).localizingCursor());
	// calculate Spearman's Rank rho value
	double rho = new SpearmanRankCorrelation().calculateSpearmanRank(cursor);
	// Rho value = -0.11...
	assertTrue(Math.abs(rho) < 0.012);
}
 
Example #19
Source File: PearsonsCorrelationTest.java    From Colocalisation_Analysis with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tests if the classic implementation of Pearson's correlation with two
 * positive correlated images produce a Pearson's R value of about 0.75.
 */
@Test
public void classicPearsonsPositiveCorrTest() throws MissingPreconditionException {
	// create a twin value range cursor that iterates over all pixels of the input data
	TwinCursor<UnsignedByteType> cursor = new TwinCursor<UnsignedByteType>(
			positiveCorrelationImageCh1.randomAccess(),
			positiveCorrelationImageCh2.randomAccess(),
			Views.iterable(positiveCorrelationAlwaysTrueMask).localizingCursor());
	// get the Pearson's value
	double pearsonsR = PearsonsCorrelation
		.classicPearsons(cursor, positiveCorrelationImageCh1Mean, positiveCorrelationImageCh2Mean);
	// check Pearsons R is close to 0.75
	assertEquals(0.75, pearsonsR, 0.01);
}
 
Example #20
Source File: TubenessTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testTubeness() {
	Img<UnsignedByteType> input = openUnsignedByteType(Ops.class,
		"TubesInput.png");
	Img<DoubleType> expected = openDoubleImg("tube.tif");

	final double scale = 5;
	final double sigma = scale / Math.sqrt(2);

	Img<DoubleType> actual = ops.create().img(input, new DoubleType());
	ops.filter().tubeness(actual, input, sigma);

	assertIterationsEqual(expected, actual);

}
 
Example #21
Source File: StatisticsTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testMax() {
	Assert.assertEquals("Max", 254d, ((UnsignedByteType) ops.run(
		IterableMax.class, randomlyFilledImg)).getRealDouble(), 0.00001d);

	// NB: should work with negative numbers
	Assert.assertEquals("Max", -1.0, ((ByteType) ops.run(IterableMax.class,
		ArrayImgs.bytes(new byte[] { -1, -2, -4, -3 }, 2, 2))).getRealDouble(),
		0.0);
}
 
Example #22
Source File: ShuffledViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testAllShuffle() {
	// FIRST - create 6x6 image filled with known values
	ArrayImg<UnsignedByteType, ByteArray> actualInputImage = ArrayImgs
		.unsignedBytes(new byte[] { //
			1, 2, 3, 4, 5, 6, //
			7, 8, 9, 10, 11, 12, //
			13, 14, 15, 16, 17, 18, //
			19, 20, 21, 22, 23, 24, //
			25, 26, 27, 28, 29, 30, //
			31, 32, 33, 34, 35, 36 //
	}, 6, 6);
	int[] blockSize = { 1, 1 };
	long seed = 0xdeadbeef;
	ShuffledView<UnsignedByteType> shuffled = new ShuffledView<>(
		actualInputImage, blockSize, seed);
	ArrayImg<UnsignedByteType, ByteArray> expected = ArrayImgs.unsignedBytes(
		new byte[] { //
			33, 19, 14, 36, 31, 32, //
			34, 21, 17, 30, 35, 1, //
			7, 28, 29, 20, 9, 12, //
			5, 18, 27, 3, 8, 2, //
			11, 25, 4, 24, 26, 6, //
			23, 10, 13, 15, 22, 16 //
		}, 6, 6);
	assertIterationsEqual(expected, Views.iterable(shuffled));
}
 
Example #23
Source File: AbstractFeatureTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param dim dimensions of the image
 * @param radii of the ellipse
 * @param offset of the ellipse
 * @return an {@link Img} of {@link BitType} filled with a ellipse
 */
@SuppressWarnings({ "deprecation" })
public Img<UnsignedByteType> getEllipsedBitImage(final long[] dim,
	final double[] radii, final double[] offset)
{

	// create empty bittype image with desired dimensions
	final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(
		dim);

	// create ellipse
	final EllipseRegionOfInterest ellipse = new EllipseRegionOfInterest();
	ellipse.setRadii(radii);

	// set origin in the center of image
	final double[] origin = new double[dim.length];
	for (int i = 0; i < dim.length; i++)
		origin[i] = dim[i] / 2;
	ellipse.setOrigin(origin);

	// get iterable intervall and cursor of ellipse
	final IterableInterval<UnsignedByteType> ii = ellipse
		.getIterableIntervalOverROI(img);
	final Cursor<UnsignedByteType> cursor = ii.cursor();

	// fill image with ellipse
	while (cursor.hasNext()) {
		cursor.next();
		cursor.get().set(255);
	}

	return img;
}
 
Example #24
Source File: ShuffledViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testNonSquareBlocks2() {
	// FIRST - create 6x6 image filled with known values
	ArrayImg<UnsignedByteType, ByteArray> actualInputImage = ArrayImgs
		.unsignedBytes(new byte[] { //
			1, 2, 3, 4, 5, 6, //
			7, 8, 9, 10, 11, 12, //
			13, 14, 15, 16, 17, 18, //
			19, 20, 21, 22, 23, 24, //
			25, 26, 27, 28, 29, 30, //
			31, 32, 33, 34, 35, 36 //
	}, 6, 6);
	int[] blockSize = { 3, 2 };
	long seed = 0xdeadbeef;
	ShuffledView<UnsignedByteType> shuffled = new ShuffledView<>(
		actualInputImage, blockSize, seed);
	ArrayImg<UnsignedByteType, ByteArray> expected = ArrayImgs.unsignedBytes(
		new byte[] { //
			25, 26, 27, 13, 14, 15, //
			31, 32, 33, 19, 20, 21, //
			1, 2, 3, 28, 29, 30, //
			7, 8, 9, 34, 35, 36, //
			4, 5, 6, 16, 17, 18, //
			10, 11, 12, 22, 23, 24 //
		}, 6, 6);
	assertIterationsEqual(expected, Views.iterable(shuffled));
}
 
Example #25
Source File: ShuffledViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public <T extends RealType<T>, U extends RealType<U>> void testDiffSeeds() {
	// FIRST - create 6x6 image filled with known values
	ArrayImg<UnsignedByteType, ByteArray> inputImage = ArrayImgs.unsignedBytes(
		new byte[] { //
			1, 2, 3, 4, 5, 6, //
			7, 8, 9, 10, 11, 12, //
			13, 14, 15, 16, 17, 18, //
			19, 20, 21, 22, 23, 24, //
			25, 26, 27, 28, 29, 30, //
			31, 32, 33, 34, 35, 36 //
		}, 6, 6);
	int[] blockSize = { 2, 2 };
	long seed1 = 0xdeadbeef;
	long seed2 = 0x22334455;
	ShuffledView<UnsignedByteType> shuffled1 = new ShuffledView<>(inputImage,
		blockSize, seed1);
	ArrayImg<UnsignedByteType, ByteArray> expected1 = ArrayImgs.unsignedBytes(
		new byte[] { //
			27, 28, 3, 4, 15, 16, //
			33, 34, 9, 10, 21, 22, //
			5, 6, 17, 18, 13, 14, //
			11, 12, 23, 24, 19, 20, //
			1, 2, 29, 30, 25, 26, //
			7, 8, 35, 36, 31, 32 //
		}, 6, 6);
	ShuffledView<UnsignedByteType> shuffled2 = new ShuffledView<>(inputImage,
		blockSize, seed2);
	ArrayImg<UnsignedByteType, ByteArray> expected2 = ArrayImgs.unsignedBytes(
		new byte[] { //
			29, 30, 25, 26, 17, 18, //
			35, 36, 31, 32, 23, 24, //
			5, 6, 27, 28, 15, 16, //
			11, 12, 33, 34, 21, 22, //
			3, 4, 13, 14, 1, 2, //
			9, 10, 19, 20, 7, 8 //
		}, 6, 6);
	assertIterationsEqual(expected1, Views.iterable(shuffled1));
	assertIterationsEqual(expected2, Views.iterable(shuffled2));
}
 
Example #26
Source File: ConvertMapTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testLossless() {

	final byte[] inArray = { 12, 122, 9, -6, 56, 34, 108, 1, 73 };
	final Img<UnsignedByteType> in = generateUnsignedByteImg(inArray);

	final float[] outArray =
		{ 134.7f, -13089.3208f, 209.3f, 0.6f, 84.0f, -543.1f, 0f, 34.908f,
			592087.0957f };
	final Img<FloatType> out = generateFloatImg(outArray);

	final Cursor<UnsignedByteType> inC1 = in.cursor();
	final Cursor<FloatType> outC1 = out.cursor();

	while (inC1.hasNext()) {
		assertNotEquals(inC1.next().getRealDouble(),
			outC1.next().getRealDouble(), 0d);
	}

	ops.run(Ops.Map.class, out, in, new ComplexToFloat32<UnsignedByteType>());

	final Cursor<UnsignedByteType> inC2 = in.cursor();
	final Cursor<FloatType> outC2 = out.cursor();

	while (inC2.hasNext()) {
		assertEquals(inC2.next().getRealDouble(), outC2.next().getRealDouble(), 0);
	}
}
 
Example #27
Source File: ConvertMapTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testLossy() {

	final float[] inArray =
		{ 12.7f, -13089.3208f, 78.023f, 0.04f, 12.01f, -1208.90f, 109432.109f,
			1204.88f, 87.6f };
	final Img<FloatType> in = generateFloatImg(inArray);

	final byte[] outArray = { 4, 123, 18, 64, 90, 120, 12, 17, 73 };
	final Img<UnsignedByteType> out = generateUnsignedByteImg(outArray);

	ops.run(Ops.Map.class, out, in, new ComplexToUint8<FloatType>());

	final Cursor<FloatType> inC = in.cursor();
	final Cursor<UnsignedByteType> outC = out.cursor();

	while (inC.hasNext()) {

		final double inV = inC.next().getRealDouble();
		final double outV = outC.next().getRealDouble();

		// values won't be equal because the conversion is lossy
		assertNotEquals(inV, outV, 0);

		// uint8 masks float values to be 8 bits
		assertEquals(Types.uint8(inV), outV, 0);

	}
}
 
Example #28
Source File: APNGWriterTest.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<UnsignedByteType> sourceImg = (ImgPlus<UnsignedByteType>)
			opener.openImgs(new TestImgLocation.Builder().name("8bit-unsigned").pixelType(
			"uint8").axes("X", "Y", "C").lengths(100, 100, 3).build()).get(0);
	testWriting(sourceImg);

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

	final ImgPlus<UnsignedByteType> sourceImg2 = (ImgPlus<UnsignedByteType>) opener
		.openImgs(new TestImgLocation.Builder().name("8bit-unsigned").pixelType(
			"uint8").axes("X", "Y").lengths(100, 100).build()).get(0);
	testWriting(sourceImg2);
}
 
Example #30
Source File: SliceTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void LoopThroughHyperSlicesTest() {
	final int xSize = 40;
	final int ySize = 50;
	final int numChannels = 3;
	final int numSlices = 25;
	final int numTimePoints = 5;

	final Img<UnsignedByteType> testImage = generateUnsignedByteArrayTestImg(true, xSize, ySize, numChannels,
			numSlices, numTimePoints);

	final int[] axisIndices = new int[3];

	// set up the axis so the resulting hyperslices are x,y,z and
	// we loop through channels and time
	axisIndices[0] = 0;
	axisIndices[1] = 1;
	axisIndices[2] = 3;

	final SlicesII<UnsignedByteType> hyperSlices = new SlicesII<>(testImage, axisIndices, true);

	final Cursor<RandomAccessibleInterval<UnsignedByteType>> c = hyperSlices.cursor();

	int numHyperSlices = 0;
	while (c.hasNext()) {
		c.fwd();
		numHyperSlices++;
		final RandomAccessibleInterval<UnsignedByteType> hyperSlice = c.get();
		assertEquals(3, hyperSlice.numDimensions());
		assertEquals(hyperSlice.dimension(0), xSize);
		assertEquals(hyperSlice.dimension(1), ySize);
		assertEquals(hyperSlice.dimension(2), numSlices);
	}

	assertEquals(numChannels * numTimePoints, numHyperSlices);

}