Search in sources :

Example 36 with MetadataRetrieve

use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.

the class ImageViewer method actionPerformed.

// -- ActionListener API methods --
/**
 * Handles menu commands.
 */
@Override
public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    if ("open".equals(cmd)) {
        wait(true);
        JFileChooser chooser = GUITools.buildFileChooser(myReader);
        wait(false);
        int rval = chooser.showOpenDialog(this);
        if (rval == JFileChooser.APPROVE_OPTION) {
            final File file = chooser.getSelectedFile();
            if (file != null)
                open(file.getAbsolutePath(), fileReader);
        }
    } else if ("save".equals(cmd)) {
        wait(true);
        JFileChooser chooser = GUITools.buildFileChooser(myWriter);
        wait(false);
        int rval = chooser.showSaveDialog(this);
        if (rval == JFileChooser.APPROVE_OPTION) {
            final File file = chooser.getSelectedFile();
            if (file != null)
                save(file.getAbsolutePath(), fileWriter);
        }
    } else if ("view".equals(cmd)) {
        if (omeMeta != null) {
            XMLWindow metaWindow = new XMLWindow("OME Metadata - " + getTitle());
            metaWindow.setDefaultCloseOperation(XMLWindow.DISPOSE_ON_CLOSE);
            Exception exception = null;
            try {
                MetadataRetrieve retrieve = omexmlService.asRetrieve(omeMeta);
                metaWindow.setXML(omexmlService.getOMEXML(retrieve));
                metaWindow.setVisible(true);
            } catch (ServiceException exc) {
                exception = exc;
            } catch (ParserConfigurationException exc) {
                exception = exc;
            } catch (SAXException exc) {
                exception = exc;
            } catch (IOException exc) {
                exception = exc;
            }
            if (exception != null) {
                LOGGER.info("Cannot display OME metadata", exception);
            }
        }
    } else if ("exit".equals(cmd))
        dispose();
    else if ("fps".equals(cmd)) {
        // HACK - JOptionPane prevents shutdown on dispose
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        String result = JOptionPane.showInputDialog(this, "Animate using space bar. How many frames per second?", "" + fps);
        try {
            fps = Integer.parseInt(result);
        } catch (NumberFormatException exc) {
            LOGGER.debug("Could not parse fps '{}'", fps, exc);
        }
    } else if ("about".equals(cmd)) {
        // HACK - JOptionPane prevents shutdown on dispose
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        String msg = "<html>" + "OME Bio-Formats package for reading and " + "converting biological file formats." + "<br>Copyright (C) 2005 - " + FormatTools.YEAR + " Open Microscopy Environment:" + "<ul>" + "<li>Board of Regents of the University of Wisconsin-Madison</li>" + "<li>Glencoe Software, Inc.</li>" + "<li>University of Dundee</li>" + "</ul>" + "<i>" + FormatTools.URL_BIO_FORMATS + "</i>" + "<br>Version " + FormatTools.VERSION + " (VCS revision " + FormatTools.VCS_REVISION + "), built on " + FormatTools.DATE + "<br><br>See <a href=\"" + "https://docs.openmicroscopy.org/bio-formats/" + FormatTools.VERSION + "/users/index.html\">" + "https://docs.openmicroscopy.org/bio-formats/" + FormatTools.VERSION + "/users/index.html</a>" + "<br>for help with using Bio-Formats.";
        ImageIcon bioFormatsLogo = new ImageIcon(IFormatHandler.class.getResource("bio-formats-logo.png"));
        JOptionPane.showMessageDialog(null, msg, "Bio-Formats", JOptionPane.INFORMATION_MESSAGE, bioFormatsLogo);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) IOException(java.io.IOException) ServiceException(loci.common.services.ServiceException) DependencyException(loci.common.services.DependencyException) SAXException(org.xml.sax.SAXException) EnumerationException(ome.xml.model.enums.EnumerationException) FormatException(loci.formats.FormatException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) JFileChooser(javax.swing.JFileChooser) ServiceException(loci.common.services.ServiceException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) MetadataRetrieve(loci.formats.meta.MetadataRetrieve)

Example 37 with MetadataRetrieve

use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.

the class CellH5Writer method setId.

// -- FormatWriter API methods --
/* @see loci.formats.FormatWriter#setId(String) */
@Override
public void setId(String id) throws FormatException, IOException {
    if (id.equals(currentId))
        return;
    super.setId(id);
    try {
        ServiceFactory factory = new ServiceFactory();
        jhdf = factory.getInstance(JHDFService.class);
        jhdf.setFileForWrite(id);
    } catch (DependencyException e) {
        throw new MissingLibraryException(JHDFServiceImpl.NO_JHDF_MSG, e);
    }
    MetadataRetrieve retrieve = getMetadataRetrieve();
    int sizeX = retrieve.getPixelsSizeX(0).getValue();
    int sizeY = retrieve.getPixelsSizeY(0).getValue();
    int sizeZ = retrieve.getPixelsSizeZ(0).getValue();
    int sizeC = retrieve.getPixelsSizeC(0).getValue();
    int sizeT = retrieve.getPixelsSizeT(0).getValue();
    int type = FormatTools.pixelTypeFromString(retrieve.getPixelsType(0).toString());
    bpp = FormatTools.getBytesPerPixel(type);
    LOGGER.info("CellH5Writer: Found image with dimensions XYZCT {}x{}x{}x{}x{}, and bits per pixel {}", sizeX, sizeY, sizeZ, sizeC, sizeT, bpp);
    String plate = "PLATE_00";
    String well = "WELL_00";
    int site = 1;
    if (retrieve.getPlateCount() > 0) {
        plate = retrieve.getPlateName(0);
        well = retrieve.getWellExternalIdentifier(0, 0);
        site = retrieve.getWellSampleIndex(0, 0, 0).getValue();
        LOGGER.info("CellH5Writer: Found plate information Plate / Well / Site {} / {} / {}", plate, well, site);
    } else {
        LOGGER.info("CellH5Writer: No plate information found. Using default values...");
    }
    jhdf.createGroup(CellH5Constants.DEFINITION + CellH5Reader.CellH5Constants.OBJECT);
    jhdf.createGroup(CellH5Constants.DEFINITION + CellH5Reader.CellH5Constants.FEATURE);
    jhdf.createGroup(CellH5Constants.DEFINITION + CellH5Reader.CellH5Constants.IMAGE);
    outputPath = String.format("/sample/0/plate/%s/experiment/%s/position/%d/image/channel", plate, well, site);
    jhdf.initIntArray(outputPath, new long[] { sizeC, sizeT, sizeZ, sizeY, sizeX }, bpp);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) MissingLibraryException(loci.formats.MissingLibraryException) JHDFService(loci.formats.services.JHDFService) DependencyException(loci.common.services.DependencyException) MetadataRetrieve(loci.formats.meta.MetadataRetrieve)

Example 38 with MetadataRetrieve

use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.

the class CellH5Writer method getPlaneCount.

/* @see loci.formats.FormatWriter#getPlaneCount() */
@Override
public int getPlaneCount() {
    MetadataRetrieve retrieve = getMetadataRetrieve();
    int c = getSamplesPerPixel();
    int type = FormatTools.pixelTypeFromString(retrieve.getPixelsType(series).toString());
    int bytesPerPixel = FormatTools.getBytesPerPixel(type);
    if (bytesPerPixel > 1 && c != 1 && c != 3) {
        return super.getPlaneCount() * c;
    }
    return super.getPlaneCount();
}
Also used : MetadataRetrieve(loci.formats.meta.MetadataRetrieve)

Example 39 with MetadataRetrieve

use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.

the class WlzWriter method setId.

// -- FormatWriter API methods --
/* @see loci.formats.FormatWriter#setId(String) */
@Override
public void setId(String id) throws FormatException, IOException {
    super.setId(id);
    try {
        ServiceFactory factory = new ServiceFactory();
        wlz = factory.getInstance(WlzService.class);
    } catch (DependencyException e) {
        throw new FormatException(NO_WLZ_MSG, e);
    }
    if (wlz != null) {
        MetadataRetrieve meta = getMetadataRetrieve();
        MetadataTools.verifyMinimumPopulated(meta, series);
        wlz.open(id, "w");
        String stageLabelName = null;
        try {
            stageLabelName = meta.getStageLabelName(0);
        } catch (NullPointerException e) {
        }
        int oX = 0;
        int oY = 0;
        int oZ = 0;
        if ((stageLabelName != null) && stageLabelName.equals(wlz.getWlzOrgLabelName())) {
            final Length stageX = meta.getStageLabelX(0);
            final Length stageY = meta.getStageLabelY(0);
            final Length stageZ = meta.getStageLabelZ(0);
            oX = (int) Math.rint(stageX.value(UNITS.REFERENCEFRAME).doubleValue());
            oY = (int) Math.rint(stageY.value(UNITS.REFERENCEFRAME).doubleValue());
            oZ = (int) Math.rint(stageZ.value(UNITS.REFERENCEFRAME).doubleValue());
        }
        int nX = meta.getPixelsSizeX(series).getValue().intValue();
        int nY = meta.getPixelsSizeY(series).getValue().intValue();
        int nZ = meta.getPixelsSizeZ(series).getValue().intValue();
        int nC = meta.getPixelsSizeC(series).getValue().intValue();
        int nT = meta.getPixelsSizeT(series).getValue().intValue();
        double vX = 1.0;
        double vY = 1.0;
        double vZ = 1.0;
        if (meta.getPixelsPhysicalSizeX(0) != null) {
            vX = meta.getPixelsPhysicalSizeX(0).value(UNITS.MICROMETER).doubleValue();
        }
        if (meta.getPixelsPhysicalSizeY(0) != null) {
            vY = meta.getPixelsPhysicalSizeY(0).value(UNITS.MICROMETER).doubleValue();
        }
        if (meta.getPixelsPhysicalSizeZ(0) != null) {
            vZ = meta.getPixelsPhysicalSizeZ(0).value(UNITS.MICROMETER).doubleValue();
        }
        int gType = FormatTools.pixelTypeFromString(meta.getPixelsType(series).toString());
        wlz.setupWrite(oX, oY, oZ, nX, nY, nZ, nC, nT, vX, vY, vZ, gType);
    }
}
Also used : WlzService(loci.formats.services.WlzService) ServiceFactory(loci.common.services.ServiceFactory) Length(ome.units.quantity.Length) DependencyException(loci.common.services.DependencyException) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) FormatException(loci.formats.FormatException)

Example 40 with MetadataRetrieve

use of loci.formats.meta.MetadataRetrieve in project bioformats by openmicroscopy.

the class Colorizer method makeLUTs.

private LUT[] makeLUTs(ColorModel[] cm, boolean colorize) {
    // lookup tables can come from one of three places (in order of precedence):
    // 1) Color attribute defined in the MetadataStore
    // 2) lookup table returned by the reader's get8BitLookupTable or
    // get16BitLookupTable methods
    // 3) EmissionWavelength attribute defined in the MetadataStore
    final ImporterOptions options = process.getOptions();
    final LUT[] luts = new LUT[cm.length];
    for (int c = 0; c < luts.length; c++) {
        if (cm[c] instanceof LUT)
            luts[c] = (LUT) cm[c];
        else if (cm[c] instanceof IndexColorModel) {
            luts[c] = new LUT((IndexColorModel) cm[c], 0, 255);
        }
        Color color = null;
        if (colorize) {
            // rather than always assuming that the first channel is red, the
            // second green, etc. we will take into account the channel color
            // metadata and the acquisition wavelength
            ImageReader reader = process.getImageReader();
            MetadataStore store = reader.getMetadataStore();
            if (store instanceof MetadataRetrieve) {
                MetadataRetrieve retrieve = (MetadataRetrieve) store;
                if (c < retrieve.getChannelCount(reader.getSeries())) {
                    ome.xml.model.primitives.Color metaColor = retrieve.getChannelColor(reader.getSeries(), c);
                    if (metaColor != null) {
                        int r = metaColor.getRed();
                        int g = metaColor.getGreen();
                        int b = metaColor.getBlue();
                        int a = metaColor.getAlpha();
                        color = new Color(r, g, b, a);
                    } else if (luts[c] == null) {
                        Length wavelength = retrieve.getChannelEmissionWavelength(reader.getSeries(), c);
                        if (wavelength != null) {
                            double wave = wavelength.value(UNITS.NANOMETER).doubleValue();
                            if (wave >= BLUE_MIN && wave < BLUE_TO_GREEN_MIN) {
                                color = Color.BLUE;
                            } else if (wave >= BLUE_TO_GREEN_MIN && wave < GREEN_TO_RED_MIN) {
                                color = Color.GREEN;
                            } else if (wave >= GREEN_TO_RED_MIN && wave <= RED_MAX) {
                                color = Color.RED;
                            }
                        }
                    }
                }
            }
        }
        if (color == null && luts[c] == null) {
            color = options.getDefaultCustomColor(c);
        }
        if (color != null) {
            luts[c] = makeLUT(color);
        }
    }
    return luts;
}
Also used : Color(java.awt.Color) LUT(ij.process.LUT) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) ImageReader(loci.formats.ImageReader) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) IndexColorModel(java.awt.image.IndexColorModel)

Aggregations

MetadataRetrieve (loci.formats.meta.MetadataRetrieve)64 FormatException (loci.formats.FormatException)11 MetadataStore (loci.formats.meta.MetadataStore)11 Length (ome.units.quantity.Length)10 ServiceFactory (loci.common.services.ServiceFactory)8 DependencyException (loci.common.services.DependencyException)7 OMEXMLService (loci.formats.services.OMEXMLService)6 RandomAccessInputStream (loci.common.RandomAccessInputStream)5 Time (ome.units.quantity.Time)5 PositiveInteger (ome.xml.model.primitives.PositiveInteger)5 ServiceException (loci.common.services.ServiceException)4 MissingLibraryException (loci.formats.MissingLibraryException)4 Test (org.testng.annotations.Test)4 IndexColorModel (java.awt.image.IndexColorModel)3 Location (loci.common.Location)3 RandomAccessOutputStream (loci.common.RandomAccessOutputStream)3 ImageReader (loci.formats.ImageReader)3 BufferedImage (java.awt.image.BufferedImage)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2