/** @deprecated Use {@link io.scif.img.IO#openImg(String, ImgOptions)}. */ public static<T extends RealType<T> & NativeType<T>> Img<T> open(final String pathOrURL) throws ImgIOException, IncompatibleTypeException { return (Img<T>) new ImgOpener().openImg(pathOrURL); // Old: //return wrap(IJ.openImage(pathOrURL)); }
/** * @param reader - An initialized {@link Reader} to use for reading image * data. * @return - the {@link ImgPlus} or null * @throws ImgIOException if there is a problem reading the image data. */ public List<SCIFIOImgPlus<?>> openImgs(final Reader reader) throws ImgIOException { return openImgs(reader, null); }
/** * Creates a new ImgOpener. The first time this method runs, an additional * Context is created and the logService is cached for future logging. * * @return A new ImgOpener instance with its own Context */ private static ImgOpener opener() { final ImgOpener opener = new ImgOpener(); if (logService == null) { synchronized (IO.class) { if (logService == null) { logService = opener.getContext().getService(LogService.class); } } } return opener; }
/** * Reads in an {@link ImgPlus} from the specified index of the given source. * Can specify a variety of options via {@link SCIFIOConfig}. * * @param source - the location of the dataset to open * @param config - {@link SCIFIOConfig} to use when opening this dataset * @return - the {@link ImgPlus} or null * @throws ImgIOException if there is a problem reading the image data. */ public List<SCIFIOImgPlus<?>> openImgs(final String source, SCIFIOConfig config) throws ImgIOException { if (config == null) { config = new SCIFIOConfig(); } final Reader r = createReader(source, config); return openImgs(r, config); }
@Override public List<net.imagej.Dataset> openAll(String source, SCIFIOConfig config) throws IOException { final ArrayList<Dataset> datasetList = new ArrayList<>(); final ImgOpener imageOpener = new ImgOpener(getContext()); try { final List<SCIFIOImgPlus<?>> openImgs = imageOpener.openImgs(source, config); for (int imgId = 0; imgId != openImgs.size(); imgId++) { final SCIFIOImgPlus<?> imgPlus = openImgs.get(imgId); @SuppressWarnings({"rawtypes", "unchecked"}) final Dataset dataset = datasetService.create((ImgPlus) imgPlus); final ImageMetadata imageMeta = imgPlus.getImageMetadata(); updateDataset(dataset, imageMeta); datasetList.add(dataset); } } catch (final ImgIOException exc) { throw new IOException(exc); } return datasetList; }
/** * @param reader - An initialized {@link Reader} to use for reading image * data. * @param config - {@link SCIFIOConfig} to use when opening this dataset * @return - the {@link ImgPlus} or null * @throws ImgIOException if there is a problem reading the image data. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public List<SCIFIOImgPlus<?>> openImgs(final Reader reader, SCIFIOConfig config) throws ImgIOException { final RealType t = getType(reader); if (config == null) { config = new SCIFIOConfig().imgOpenerSetComputeMinMax(true); } final ImgFactoryHeuristic heuristic = getHeuristic(config); ImgFactory imgFactory; try { if (t instanceof NativeType) { imgFactory = heuristic.createFactory(reader.getMetadata(), // config.imgOpenerGetImgModes(), (NativeType) t); } else return null; } catch (final IncompatibleTypeException e) { throw new ImgIOException(e); } return openImgs(reader, imgFactory, config); }
/** * Tests using the {@link ImgOpener} when opening a non-String source. */ @Test public void testOpenNonString() throws ImgIOException, IOException, FormatException { final Context c = imgOpener.getContext(); final SCIFIO scifio = new SCIFIO(c); // Make a GIF byte array // - From http://giflib.sourceforge.net/whatsinagif/bits_and_bytes.html final byte[] bytes = new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x0A, 0x00, 0x0A, 0x00, (byte) 0x91, 0x00, 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0x00, 0x00, 0x00, 0x00, (byte) 0xFF, 0x00, 0x00, 0x00, 0x21, (byte) 0xF9, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x0A, 0x00, 0x00, 0x02, 0x16, (byte) 0x8C, 0x2D, (byte) 0x99, (byte) 0x87, 0x2A, 0x1C, (byte) 0xDC, 0x33, (byte) 0xA0, 0x02, 0x75, (byte) 0xEC, (byte) 0x95, (byte) 0xFA, (byte) 0xA8, (byte) 0xDE, 0x60, (byte) 0x8C, 0x04, (byte) 0x91, 0x4C, 0x01, 0x00, 0x3B }; final RandomAccessInputStream stream = new RandomAccessInputStream(c, bytes); //Get the appropriate format final Format format = scifio.format().getFormat(stream); // Create and initialize a reader final Reader r = format.createReader(); r.setSource(stream); // Open an ImgPlus from the reader ImgPlus<?> img = imgOpener.openImgs(r).get(0); assertNotNull(img); }
public ArrayImgLoader( final T type ) { opener = new ImgOpener(); factory = new ArrayImgFactory<>(); this.type = type; }
/** * @param reader - An initialized {@link Reader} to use for reading image * data. * @param type - The {@link Type} T of the output {@link ImgPlus}, which must * match the typing of the {@link ImgFactory}. * @param config - {@link SCIFIOConfig} to use when opening this dataset * @return - the {@link ImgPlus} or null * @throws ImgIOException if there is a problem reading the image data. */ public <T extends RealType<T> & NativeType<T>> List<SCIFIOImgPlus<T>> openImgs(final Reader reader, final T type, SCIFIOConfig config) throws ImgIOException { if (config == null) { config = new SCIFIOConfig().imgOpenerSetComputeMinMax(true); } final ImgFactoryHeuristic heuristic = getHeuristic(config); ImgFactory<T> imgFactory; try { imgFactory = heuristic.createFactory(reader.getMetadata(), config .imgOpenerGetImgModes(), type); } catch (final IncompatibleTypeException e) { throw new ImgIOException(e); } return openImgs(reader, imgFactory, config); }
return opener.openImg( fn, factory, type );
/** * @param source - Dataset source to open * @param config - Options object for opening this dataset * @return A Reader initialized to open the specified id */ private Reader createReader(final String source, final SCIFIOConfig config) throws ImgIOException { final boolean computeMinMax = config.imgOpenerIsComputeMinMax(); statusService.showStatus("Initializing " + source); ReaderFilter r = null; try { r = initializeService.initializeReader(source, config); r.enable(ChannelFiller.class); r.enable(PlaneSeparator.class).separate(axesToSplit(r)); if (computeMinMax) r.enable(MinMaxFilter.class); } catch (final FormatException e) { throw new ImgIOException(e); } catch (final IOException e) { throw new ImgIOException(e); } return r; }
@Override public List<net.imagej.Dataset> openAll(String source, SCIFIOConfig config) throws IOException { final ArrayList<Dataset> datasetList = new ArrayList<>(); final ImgOpener imageOpener = new ImgOpener(getContext()); try { final List<SCIFIOImgPlus<?>> openImgs = imageOpener.openImgs(source, config); for (int imgId = 0; imgId != openImgs.size(); imgId++) { final SCIFIOImgPlus<?> imgPlus = openImgs.get(imgId); @SuppressWarnings({"rawtypes", "unchecked"}) final Dataset dataset = datasetService.create((ImgPlus) imgPlus); final ImageMetadata imageMeta = imgPlus.getImageMetadata(); updateDataset(dataset, imageMeta); datasetList.add(dataset); } } catch (final ImgIOException exc) { throw new IOException(exc); } return datasetList; }
/** * Reads in an {@link ImgPlus} from the specified index of the given source. * Can specify a variety of options via {@link SCIFIOConfig}. * * @param source - the location of the dataset to open * @param config - {@link SCIFIOConfig} to use when opening this dataset * @return - the {@link ImgPlus} or null * @throws ImgIOException if there is a problem reading the image data. */ public List<SCIFIOImgPlus<?>> openImgs(final String source, SCIFIOConfig config) throws ImgIOException { if (config == null) { config = new SCIFIOConfig(); } final Reader r = createReader(source, config); return openImgs(r, config); }
/** * @param reader - An initialized {@link Reader} to use for reading image * data. * @param config - {@link SCIFIOConfig} to use when opening this dataset * @return - the {@link ImgPlus} or null * @throws ImgIOException if there is a problem reading the image data. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public List<SCIFIOImgPlus<?>> openImgs(final Reader reader, SCIFIOConfig config) throws ImgIOException { final RealType t = getType(reader); if (config == null) { config = new SCIFIOConfig().imgOpenerSetComputeMinMax(true); } final ImgFactoryHeuristic heuristic = getHeuristic(config); ImgFactory imgFactory; try { if (t instanceof NativeType) { imgFactory = heuristic.createFactory(reader.getMetadata(), // config.imgOpenerGetImgModes(), (NativeType) t); } else return null; } catch (final IncompatibleTypeException e) { throw new ImgIOException(e); } return openImgs(reader, imgFactory, config); }
public LegacyStackImageLoader( final HashMap< ViewId, String > filenames, final boolean useImageJOpener ) { this.filenames = filenames; this.useImageJOpener = useImageJOpener; opener = useImageJOpener ? null : new ImgOpener( new Context( SCIFIOService.class, AppService.class, StatusService.class ) ); factory = new ArrayImgFactory<>(); type = new UnsignedShortType(); }
/** * @param reader - An initialized {@link Reader} to use for reading image * data. * @param type - The {@link Type} T of the output {@link ImgPlus}, which must * match the typing of the {@link ImgFactory}. * @param config - {@link SCIFIOConfig} to use when opening this dataset * @return - the {@link ImgPlus} or null * @throws ImgIOException if there is a problem reading the image data. */ public <T extends RealType<T> & NativeType<T>> List<SCIFIOImgPlus<T>> openImgs(final Reader reader, final T type, SCIFIOConfig config) throws ImgIOException { if (config == null) { config = new SCIFIOConfig().imgOpenerSetComputeMinMax(true); } final ImgFactoryHeuristic heuristic = getHeuristic(config); ImgFactory<T> imgFactory; try { imgFactory = heuristic.createFactory(reader.getMetadata(), config .imgOpenerGetImgModes(), type); } catch (final IncompatibleTypeException e) { throw new ImgIOException(e); } return openImgs(reader, imgFactory, config); }
/** * @param source - Dataset source to open * @param config - Options object for opening this dataset * @return A Reader initialized to open the specified id */ private Reader createReader(final String source, final SCIFIOConfig config) throws ImgIOException { final boolean computeMinMax = config.imgOpenerIsComputeMinMax(); statusService.showStatus("Initializing " + source); ReaderFilter r = null; try { r = initializeService.initializeReader(source, config); r.enable(ChannelFiller.class); r.enable(PlaneSeparator.class).separate(axesToSplit(r)); if (computeMinMax) r.enable(MinMaxFilter.class); } catch (final FormatException e) { throw new ImgIOException(e); } catch (final IOException e) { throw new ImgIOException(e); } return r; }
/** * Reads in an {@link ImgPlus} from the first image of the given source. * * @param source - the location of the dataset to open * @return - the {@link ImgPlus} or null * @throws ImgIOException if there is a problem reading the image data. */ public List<SCIFIOImgPlus<?>> openImgs(final String source) throws ImgIOException { return openImgs(source, (SCIFIOConfig) null); }
@Override public Dataset open(final String 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); } }
/** * @param source - the location of the dataset to open * @param imgFactory - The {@link ImgFactory} to use for creating the * resultant {@link ImgPlus}. * @param config - {@link SCIFIOConfig} to use when opening this dataset * @return - the {@link ImgPlus} or null * @throws ImgIOException if there is a problem reading the image data. */ public <T extends RealType<T> & NativeType<T>> List<SCIFIOImgPlus<T>> openImgs( final String source, final ImgFactory<T> imgFactory, SCIFIOConfig config) throws ImgIOException { if (config == null) { config = new SCIFIOConfig().imgOpenerSetComputeMinMax(true); } final Reader r = createReader(source, config); return openImgs(r, imgFactory, config); }