net.imagej.ImgPlus Java Examples
The following examples show how to use
net.imagej.ImgPlus.
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: TiffFormatTest.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testNoCompression() throws IOException { final int[] formats = new int[] { FormatTools.INT8, FormatTools.UINT8, FormatTools.INT16, FormatTools.UINT16, FormatTools.INT32, FormatTools.UINT32, FormatTools.FLOAT, FormatTools.DOUBLE }; final SCIFIOConfig config = new SCIFIOConfig(); config.writerSetCompression(CompressionType.UNCOMPRESSED.toString()); for (final int f : formats) { final String formatString = FormatTools.getPixelTypeString(f); final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder() .name("testimg").pixelType(formatString).axes("X", "Y", "C").lengths( 100, 100, 3).build()).get(0); testWriting(sourceImg, config); } }
Example #2
Source File: TiffFormatTest.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testJ2kLossyCompression() throws IOException { final int[] formats = new int[] { FormatTools.INT8, FormatTools.UINT8, FormatTools.INT16, FormatTools.UINT16, FormatTools.INT32, FormatTools.UINT32, FormatTools.FLOAT, FormatTools.DOUBLE }; final SCIFIOConfig config = new SCIFIOConfig(); config.writerSetCompression(CompressionType.J2K_LOSSY.toString()); for (final int f : formats) { final String formatString = FormatTools.getPixelTypeString(f); final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder() .name("testimg").pixelType(formatString).axes("X", "Y", "C").lengths( 100, 100, 3).build()).get(0); testWriting(sourceImg, config); } }
Example #3
Source File: PlanarAccessConverter.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
/** Populates plane by reference using {@link PlanarAccess} interface. */ @Override @SuppressWarnings("unchecked") public <T extends RealType<T>> void populatePlane(final Reader reader, final int imageIndex, final int planeIndex, final byte[] plane, final ImgPlus<T> planarImg, final SCIFIOConfig config) { final Metadata m = reader.getMetadata(); @SuppressWarnings("rawtypes") final PlanarAccess planarAccess = imgUtilService.getPlanarAccess(planarImg); final int pixelType = m.get(imageIndex).getPixelType(); final int bpp = FormatTools.getBytesPerPixel(pixelType); final boolean fp = FormatTools.isFloatingPoint(pixelType); final boolean little = m.get(imageIndex).isLittleEndian(); Object planeArray = Bytes.makeArray(plane, bpp, fp, little); if (planeArray == plane) { // array was returned by reference; make a copy final byte[] planeCopy = new byte[plane.length]; System.arraycopy(plane, 0, planeCopy, 0, plane.length); planeArray = planeCopy; } planarAccess.setPlane(planeIndex, imgUtilService.makeArray(planeArray)); }
Example #4
Source File: AbstractSyntheticWriterTest.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
/** * @param configuration Configuration to use for saving * @return The {@link FileLocation} saeved to. */ public FileLocation testOverwritingBehavior(SCIFIOConfig configuration) throws IOException { Context ctx = new Context(); try { final FileLocation saveLocation = createTempFileLocation("test" + suffix); ImgSaver saver = new ImgSaver(ctx); ImgOpener opener = new ImgOpener(ctx); ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder() .name("testimg").pixelType("uint8").axes("X", "Y").lengths(100, 100) .build()).get(0); saver.saveImg(saveLocation, sourceImg, configuration); saver.saveImg(saveLocation, sourceImg, configuration); return saveLocation; } finally { ctx.dispose(); } }
Example #5
Source File: ImgOpener.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
private void populateMinMax(final Reader r, final ImgPlus<?> imgPlus, final int imageIndex) { final int sizeC = (int) r.getMetadata().get(imageIndex).getAxisLength( Axes.CHANNEL); final ReaderFilter rf = (ReaderFilter) r; final MinMaxFilter minMax = rf.enable(MinMaxFilter.class); for (int c = 0; c < sizeC; c++) { final Double min = minMax.getAxisKnownMinimum(imageIndex, Axes.CHANNEL, c); final Double max = minMax.getAxisKnownMinimum(imageIndex, Axes.CHANNEL, c); imgPlus.setChannelMinimum(c, min == null ? Double.NaN : min); imgPlus.setChannelMaximum(c, max == null ? Double.NaN : max); } }
Example #6
Source File: TiffFormatTest.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testLZWCompression() throws IOException { final int[] formats = new int[] { FormatTools.INT8, FormatTools.UINT8, FormatTools.INT16, FormatTools.UINT16, FormatTools.INT32, FormatTools.UINT32, FormatTools.FLOAT, FormatTools.DOUBLE }; final SCIFIOConfig config = new SCIFIOConfig(); config.writerSetCompression(CompressionType.LZW.toString()); for (final int f : formats) { final String formatString = FormatTools.getPixelTypeString(f); final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder() .name("testimg").pixelType(formatString).axes("X", "Y", "C").lengths( 100, 100, 3).build()).get(0); testWriting(sourceImg, config); } }
Example #7
Source File: TiffFormatTest.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testJ2kCompression() throws IOException { final int[] formats = new int[] { FormatTools.INT8, FormatTools.UINT8, FormatTools.INT16, FormatTools.UINT16, FormatTools.INT32, FormatTools.UINT32, FormatTools.FLOAT }; final SCIFIOConfig config = new SCIFIOConfig(); config.writerSetCompression(CompressionType.J2K.toString()); for (final int f : formats) { final String formatString = FormatTools.getPixelTypeString(f); final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder() .name("testimg").pixelType(formatString).axes("X", "Y", "C").lengths( 100, 100, 3).build()).get(0); testWriting(sourceImg, config); } }
Example #8
Source File: APNGWriterTest.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
@SuppressWarnings("unchecked") @Test public void testWriting_uint16() throws IOException { final ImgPlus<ByteType> sourceImg = (ImgPlus<ByteType>) opener.openImgs( new TestImgLocation.Builder().name("16bit-unsigned").pixelType("uint16") .axes("X", "Y", "C").lengths(100, 100, 3).build()).get(0); testWriting(sourceImg); final ImgPlus<ByteType> sourceImg2 = (ImgPlus<ByteType>) opener.openImgs( new TestImgLocation.Builder().name("16bit-unsigned").pixelType("uint16") .axes("X", "Y").lengths(100, 100).build()).get(0); testWriting(sourceImg2); }
Example #9
Source File: DefaultDatasetIOService.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public Metadata save(final Dataset dataset, final Location destination, final SCIFIOConfig config) throws IOException { @SuppressWarnings("rawtypes") final ImgPlus img = dataset.getImgPlus(); final Metadata metadata; final ImgSaver imageSaver = new ImgSaver(getContext()); try { metadata = imageSaver.saveImg(destination, img, config); } catch (ImgIOException | IncompatibleTypeException exc) { throw new IOException(exc); } final String name = destination.getName(); dataset.setName(name); dataset.setDirty(false); return metadata; }
Example #10
Source File: DefaultDatasetIOService.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public Dataset open(final Location source, final SCIFIOConfig config) throws IOException { final ImgOpener imageOpener = new ImgOpener(getContext()); try { // TODO openImgs we are only using the first image index in the // SCIFIOConfig.imgOpenerGetRange - so this image index corresponds to the // first ImgPlus in the list returned by the ImgOpener. See // https://github.com/scifio/scifio/issues/259 final SCIFIOImgPlus<?> imgPlus = imageOpener.openImgs(source, config).get( 0); @SuppressWarnings({ "rawtypes", "unchecked" }) final Dataset dataset = datasetService.create((ImgPlus) imgPlus); final ImageMetadata imageMeta = imgPlus.getImageMetadata(); updateDataset(dataset, imageMeta); return dataset; } catch (final ImgIOException exc) { throw new IOException(exc); } }
Example #11
Source File: JPEGWriterTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@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).planarDims(3) .build()).get(0); testWritingApprox(sourceImg, 58.1647058823); }
Example #12
Source File: ManualReadImg.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
private static void readImg(final File file) throws Exception { final ImgPlus<?> img = IO.open(new FileLocation(file.getAbsolutePath())); System.out.println("file = " + file); System.out.println("Dimensions:"); for (int d = 0; d < img.numDimensions(); d++) { final CalibratedAxis axisType = img.axis(d); final long axisLength = img.dimension(d); System.out.println("\t" + axisLength + " : " + axisType.type() .getLabel()); } }
Example #13
Source File: ConvertImg.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
private static void convertImg(final File file) throws Exception { final Context c = new Context(); final SCIFIOConfig config = new SCIFIOConfig().imgOpenerSetImgModes( ImgMode.ARRAY); final ImgPlus<?> img = new ImgOpener(c).openImgs(new FileLocation(file .getAbsolutePath()), config).get(0); final String outPath = file.getParent() + File.separator + "out_" + img .getName(); new ImgSaver(c).saveImg(new FileLocation(outPath), img); c.dispose(); }
Example #14
Source File: ICSFormatTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testWriting_int16() throws IOException { final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("int16").axes("X", "Y", "C").lengths(100, 100, 3) .build()).get(0); testWriting(sourceImg); }
Example #15
Source File: AbstractSyntheticWriterTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) public void testWritingApprox(final ImgPlus<?> sourceImg, final SCIFIOConfig config, final double delta) throws IOException { final FileLocation out = createTempFileLocation(suffix); final Context ctx = new Context(); new ImgSaver(ctx).saveImg(out, sourceImg, config); final ImgPlus<?> written = new ImgOpener(ctx).openImgs(out).get(0); ctx.dispose(); final Cursor<RealType> inC = (Cursor<RealType>) sourceImg.cursor(); final RandomAccess<RealType> readRA = (RandomAccess<RealType>) written .randomAccess(); double source; double read; double totalDelta = 0; final int[] pos = Intervals.dimensionsAsIntArray(sourceImg); final NormalizerUtil n = new NormalizerUtil(inC.get().getMaxValue(), inC .get().getMinValue()); while (inC.hasNext()) { source = n.normalize(inC.next().getRealDouble()); inC.localize(pos); readRA.setPosition(pos); read = n.normalize(readRA.get().getRealDouble()); totalDelta += Math.abs(source - read); } assertEquals(delta, totalDelta, 0.000_0001); }
Example #16
Source File: AbstractSyntheticWriterTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
public void testWriting(final ImgPlus<?> sourceImg, final SCIFIOConfig config) throws IOException { final FileLocation out = createTempFileLocation(suffix); final Context ctx = new Context(); new ImgSaver(ctx).saveImg(out, sourceImg, config); final ImgPlus<?> written = new ImgOpener(ctx).openImgs(out).get(0); ctx.dispose(); assertEquals(ImageHash.hashImg(written), ImageHash.hashImg(sourceImg)); }
Example #17
Source File: ICSFormatTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testWriting_float() throws IOException { final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("float").axes("X", "Y", "C").lengths(100, 100, 3) .build()).get(0); testWriting(sourceImg); }
Example #18
Source File: ICSFormatTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testWriting_uint8() throws IOException { final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("uint8").axes("X", "Y", "C").lengths(100, 100, 3) .build()).get(0); testWriting(sourceImg); final ImgPlus<?> sourceImg2 = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("uint8").axes("X", "Y", "C", "Time").lengths(100, 100, 3, 3).build()).get(0); testWriting(sourceImg2); final ImgPlus<?> sourceImg3 = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("uint8").axes("X", "Y", "Channel", "Z", "Time") .lengths(100, 100, 3, 10, 13).build()).get(0); testWriting(sourceImg3); final ImgPlus<?> sourceImg4 = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("uint8").axes("X", "Y", "C", "Z", "T").lengths(100, 100, 3, 3, 3).build()).get(0); testWriting(sourceImg4); final ImgPlus<?> sourceImg5 = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("uint8").axes("X", "Y", "Z", "Custom").lengths(100, 100, 3, 3).build()).get(0); testWriting(sourceImg5); final ImgPlus<?> sourceImg6 = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("uint8").axes("X", "Y").lengths(100, 100).build()).get(0); testWriting(sourceImg6); }
Example #19
Source File: ICSFormatTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testWriting_int8() throws IOException { final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("int8").axes("X", "Y", "C").lengths(100, 100, 3) .build()).get(0); testWriting(sourceImg); }
Example #20
Source File: JPEG2000FormatTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testWriting_int8() throws IOException { final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("int8").axes("X", "Y", "C").lengths(100, 100, 3) .build()).get(0); testWritingApprox(sourceImg, 29515.294117642843); }
Example #21
Source File: ICSFormatTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testWriting_uint32() throws IOException { final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("uint32").axes("X", "Y", "C").lengths(100, 100, 3) .build()).get(0); testWriting(sourceImg); }
Example #22
Source File: TiffFormatTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
public void testJPEGCompression() throws IOException { final int[] formats = new int[] { FormatTools.INT8, FormatTools.UINT8, FormatTools.INT16, FormatTools.UINT16 }; final SCIFIOConfig config = new SCIFIOConfig(); config.writerSetCompression(CompressionType.JPEG.toString()); for (final int f : formats) { final String formatString = FormatTools.getPixelTypeString(f); final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder() .name("testimg").pixelType(formatString).axes("X", "Y", "C").lengths( 100, 100, 3).build()).get(0); testWriting(sourceImg, config); } }
Example #23
Source File: EPSWriterTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@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 #24
Source File: EPSWriterTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@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 #25
Source File: APNGWriterTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@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 #26
Source File: JPEG2000FormatTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testWriting_uint32() throws IOException { final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("uint32").axes("X", "Y", "C").lengths(100, 100, 3) .build()).get(0); testWritingApprox(sourceImg, 0.00036388822); }
Example #27
Source File: JPEG2000FormatTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testWriting_int32() throws IOException { final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("int32").axes("X", "Y", "C").lengths(100, 100, 3) .build()).get(0); testWritingApprox(sourceImg, 14699.999640880153); }
Example #28
Source File: JPEG2000FormatTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testWriting_uint16() throws IOException { final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("uint16").axes("X", "Y", "C").lengths(100, 100, 3) .build()).get(0); testWritingApprox(sourceImg, 17.26710917830161); }
Example #29
Source File: JPEG2000FormatTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testWriting_int16() throws IOException { final ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder().name( "testimg").pixelType("int16").axes("X", "Y", "C").lengths(100, 100, 3) .build()).get(0); testWritingApprox(sourceImg, 21889.002059970047); }
Example #30
Source File: QTWriterTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@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); }