@Override public SCIFIOImgPlus<T> copy() { final SCIFIOImgPlus<T> copy = new SCIFIOImgPlus<>(getImg().copy(), this); copy.setMetadata(getMetadata()); return copy; }
/** * Counts the number of slices in the provided ImgPlus. * <p> * NumSlices = product of the sizes of all non-X,Y planes. * </p> */ private int countSlices(final SCIFIOImgPlus<?> img) { int sliceCount = 1; for (int i = 0; i < img.numDimensions(); i++) { if (!(img.axis(i).type().equals(Axes.X) || img.axis(i).type().equals( Axes.Y))) { sliceCount *= img.dimension(i); } } return sliceCount; }
/** * As {@link #saveImg(Writer, SCIFIOImgPlus, int)}, with configuration * options. * * @param w * @param img * @param config Configuration information to use for this write. * @throws ImgIOException * @throws IncompatibleTypeException */ public void saveImg(final Writer w, final SCIFIOImgPlus<?> img, final int imageIndex, final SCIFIOConfig config) throws ImgIOException, IncompatibleTypeException { writeImg(img.getSource(), w, img, imageIndex, config); }
/** * @param imageIndex - Image index to look up the color table * @param planeIndex - Plane index of the desired color table * @return The ColorTable of the underlying dataset at the specified indices. */ public ColorTable getColorTable(final int imageIndex, final int planeIndex) { ColorTable table = super.getColorTable(planeIndex); if (table == null && SCIFIOCellImg.class.isAssignableFrom(getImg().getClass())) { try { table = ((SCIFIOCellImg<?, ?>) getImg()).getColorTable(imageIndex, planeIndex); } catch (final FormatException e) { return null; } catch (final IOException e) { return null; } setColorTable(table, planeIndex); } return table; }
throws FormatException, IOException, ImgIOException statusService.showStatus("Initializing " + img.getName()); final Metadata meta = w.getFormat().createMetadata(); Metadata imgMeta = img.getMetadata(); final List<ImageMetadata> imageMeta = new ArrayList<>(); final int pixelType = utils().makeType(img.firstElement()); final CalibratedAxis[] axes = new CalibratedAxis[img.numDimensions()]; img.axes(axes); final long[] axisLengths = new long[img.numDimensions()]; img.dimensions(axisLengths); iMeta.populate(img.getName(), Arrays.asList(axes), axisLengths, pixelType, true, false, false, false, true); if (img.getCompositeChannelCount() > 1) { if (config.imgSaverGetWriteRGB()) { iMeta.setPlanarAxisCount(3); if (iMeta.getAxisLength(Axes.CHANNEL) > img.getCompositeChannelCount()) img.getCompositeChannelCount()); iMeta.setAxisLength(Axes.CHANNEL, img.getCompositeChannelCount());
@Override public void dispose() { final Object img = getImg(); if (img instanceof Disposable) { ((Disposable) img).dispose(); } }
new SCIFIOImgPlus<>(img, name, dimTypes, cal); final String metaName = meta.get(imageIndex).getName(); if (metaName != null) imgPlus.setName(metaName); imgPlus.setValidBits(validBits); imgPlus.setCompositeChannelCount(compositeChannelCount);
/** * Test that when a {@link SCIFIOCellImg} is opened and disposed, the * associated reader is closed. */ @Test public void testReaderCleanup() { // Make an id that will trigger cell creation final String id = "lotsofplanes&axes=X,Y,Z&lengths=256,256,100000.fake"; final SCIFIOImgPlus<?> img = IO.open(id); assertNotNull(((SCIFIOCellImg) img.getImg()).reader().getMetadata()); img.dispose(); assertNull(((SCIFIOCellImg) img.getImg()).reader().getMetadata()); }
private static void fillInfo(final ImagePlus imp, final ImgPlus<? extends RealType<?>> imgPlus) { if (imgPlus instanceof SCIFIOImgPlus) { final SCIFIOImgPlus<?> scifioImgPlus = (SCIFIOImgPlus<?>)imgPlus; final Metadata meta = scifioImgPlus.getMetadata(); if (meta != null) { fillImageInfo(imp, meta); addInfo(imp, "--- Global Metadata ---"); fillInfo(imp, meta.getTable()); addInfo(imp, "--- Image Metadata ---"); for (final ImageMetadata iMeta : meta.getAll()) { fillInfo(imp, iMeta.getTable()); } } } }
/** * Populates the calibration units of the given {@link SCIFIOImgPlus}, using * the provided {@link Metadata}. */ private <T extends RealType<T>> void setCalibrationUnits( final SCIFIOImgPlus<T> imgPlus, final Metadata m, final int imageIndex) { for (final CalibratedAxis axis : m.get(imageIndex).getAxes()) { final int index = imgPlus.dimensionIndex(axis.type()); if (index >= 0) { imgPlus.axis(index).setUnit(axis.unit()); } } }
/** * Tests that opening datasets with multiple images, via * {@link SCIFIOConfig#imgOpenerGetRange()}, is working as intended. * * @throws ImgIOException */ @Test public void testOpenImageRange() throws ImgIOException { final String id = "testImg&images=5&lengths=512,512&axes=X,Y.fake"; // Open images 0 and 3 final List<SCIFIOImgPlus<?>> imgs = new MultiImgOpener().openImgs(id, new SCIFIOConfig() .imgOpenerSetRange("0,3")); // Check the size assertEquals(2, imgs.size()); // Check the adjusted dimensions assertEquals(imgs.get(0).dimension(0), imgs.get(1).dimension(0) + 30); assertEquals(imgs.get(0).dimension(1), imgs.get(1).dimension(1) + 30); }
@Override public <T> SCIFIOImgPlus<T> makeSCIFIOImgPlus(final Img<T> img) { if (img instanceof SCIFIOImgPlus) return (SCIFIOImgPlus<T>) img; if (img instanceof ImgPlus) { return new SCIFIOImgPlus<>((ImgPlus<T>) img); } return new SCIFIOImgPlus<>(img); }
throws FormatException, IOException, ImgIOException statusService.showStatus("Initializing " + img.getName()); final Metadata meta = w.getFormat().createMetadata(); Metadata imgMeta = img.getMetadata(); final List<ImageMetadata> imageMeta = new ArrayList<>(); final int pixelType = utils().makeType(img.firstElement()); final CalibratedAxis[] axes = new CalibratedAxis[img.numDimensions()]; img.axes(axes); final long[] axisLengths = new long[img.numDimensions()]; img.dimensions(axisLengths); iMeta.populate(img.getName(), Arrays.asList(axes), axisLengths, pixelType, true, false, false, false, true); if (img.getCompositeChannelCount() > 1) { if (config.imgSaverGetWriteRGB()) { iMeta.setPlanarAxisCount(3); if (iMeta.getAxisLength(Axes.CHANNEL) > img.getCompositeChannelCount()) img.getCompositeChannelCount()); iMeta.setAxisLength(Axes.CHANNEL, img.getCompositeChannelCount());
@Override public void dispose() { final Object img = getImg(); if (img instanceof Disposable) { ((Disposable) img).dispose(); } }
/** * @param imageIndex - Image index to look up the color table * @param planeIndex - Plane index of the desired color table * @return The ColorTable of the underlying dataset at the specified indices. */ public ColorTable getColorTable(final int imageIndex, final int planeIndex) { ColorTable table = super.getColorTable(planeIndex); if (table == null && SCIFIOCellImg.class.isAssignableFrom(getImg().getClass())) { try { table = ((SCIFIOCellImg<?, ?>) getImg()).getColorTable(imageIndex, planeIndex); } catch (final FormatException e) { return null; } catch (final IOException e) { return null; } setColorTable(table, planeIndex); } return table; }
new SCIFIOImgPlus<>(img, name, dimTypes, cal); final String metaName = meta.get(imageIndex).getName(); if (metaName != null) imgPlus.setName(metaName); imgPlus.setValidBits(validBits); imgPlus.setCompositeChannelCount(compositeChannelCount);
public static OMEXMLMetadata getOMEXMLMetadata(Dataset data, ImageJ ij) { ImgPlus<?> imp = data.getImgPlus(); if (!(imp instanceof SCIFIOImgPlus)) { ij.ui().showDialog("This image has not been opened with SCIFIO.", DialogPrompt.MessageType.ERROR_MESSAGE); return null; } SCIFIOImgPlus<?> sciImp = (SCIFIOImgPlus<?>) imp; Metadata metadata = sciImp.getMetadata(); // Why the fuck this is needed ? while ((metadata instanceof AbstractMetadataWrapper)) { metadata = ((AbstractMetadataWrapper) metadata).unwrap(); } // Check if metadata are OME or not if (!(metadata instanceof OMETIFFFormat.Metadata)) { ij.ui().showDialog("This file does not contain OME metadata", DialogPrompt.MessageType.ERROR_MESSAGE); return null; } OMETIFFFormat.Metadata omeMeta = ((OMETIFFFormat.Metadata) metadata); OMEXMLMetadata ome = omeMeta.getOmeMeta().getRoot(); return ome; }
/** * Populates the calibration units of the given {@link SCIFIOImgPlus}, using * the provided {@link Metadata}. */ private <T extends RealType<T>> void setCalibrationUnits( final SCIFIOImgPlus<T> imgPlus, final Metadata m, final int imageIndex) { for (final CalibratedAxis axis : m.get(imageIndex).getAxes()) { final int index = imgPlus.dimensionIndex(axis.type()); if (index >= 0) { imgPlus.axis(index).setUnit(axis.unit()); } } }
/** * Tests that opening datasets with multiple images, via * {@link SCIFIOConfig#imgOpenerIsOpenAllImages()} is working as intended. * * @throws ImgIOException */ @Test public void testOpenAllImages() throws ImgIOException { final String id = "testImg&images=5&lengths=512,512&axes=X,Y.fake"; // Open all images final List<SCIFIOImgPlus<?>> imgs = new MultiImgOpener().openImgs(id, new SCIFIOConfig() .imgOpenerSetOpenAllImages(true)); // Check the size assertEquals(5, imgs.size()); // Check the adjusted dimensions SCIFIOImgPlus<?> img = imgs.get(0); for (int i = 1; i < imgs.size(); i++) { final SCIFIOImgPlus<?> testImg = imgs.get(i); assertEquals(img.dimension(0), testImg.dimension(0) + 10); assertEquals(img.dimension(1), testImg.dimension(1) + 10); img = testImg; } }
@Override public <T> SCIFIOImgPlus<T> makeSCIFIOImgPlus(final Img<T> img) { if (img instanceof SCIFIOImgPlus) return (SCIFIOImgPlus<T>) img; if (img instanceof ImgPlus) { return new SCIFIOImgPlus<>((ImgPlus<T>) img); } return new SCIFIOImgPlus<>(img); }