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?");
}
}
Aggregations