Search in sources :

Example 1 with ImgOpener

use of io.scif.img.ImgOpener in project imagej-ops by imagej.

the class ColocalisationTest method loadTiffFromJar.

/**
 * Loads a Tiff file from within the jar to use as a mask Cursor.
 * So we use Img<T> which has a cursor() method.
 * The given path is treated
 * as relative to this tests-package (i.e. "Data/test.tiff" refers
 * to the test.tiff in sub-folder Data).
 *
 * @param <T> The wanted output type.
 * @param relPath The relative path to the Tiff file.
 * @return The file as ImgLib image.
 */
private <T extends RealType<T> & NativeType<T>> Img<T> loadTiffFromJar(final String relPath) {
    // InputStream is = TestImageAccessor.class.getResourceAsStream(relPath);
    // BufferedInputStream bis = new BufferedInputStream(is);
    final ImgOpener opener = new ImgOpener(context);
    // HACK: Read data from file system for now.
    // Until this is fixed, the test will not pass when run from a JAR file.
    String source = "src/test/resources/net/imagej/ops/coloc/" + relPath;
    try {
        return (Img) opener.openImgs(source).get(0);
    } catch (final ImgIOException exc) {
        throw new IllegalStateException("File " + relPath + " is unexpectedly inaccessible?");
    }
}
Also used : Img(net.imglib2.img.Img) ImgIOException(io.scif.img.ImgIOException) ImgOpener(io.scif.img.ImgOpener)

Aggregations

ImgIOException (io.scif.img.ImgIOException)1 ImgOpener (io.scif.img.ImgOpener)1 Img (net.imglib2.img.Img)1