Java Code Examples for loci.formats.IFormatReader#getSizeX()

The following examples show how to use loci.formats.IFormatReader#getSizeX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Calibration.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public Point[] getTileIndices(IFormatReader reader, int tileWidth, int tileHeight) {
    Rectangle region = new Rectangle(0, 0, reader.getSizeX()+1, reader.getSizeY() + 1);
    int minTileX = XToTileX(region.x,0,tileWidth);
    int maxTileX = XToTileX(region.x + region.width - 1,0,tileWidth);
    int minTileY = this.YToTileY(region.y,0,tileHeight);
    int maxTileY = this.YToTileY(region.y + region.height - 1,0,tileHeight);
    Point[] tileIndices = new Point[(maxTileY - minTileY + 1) * (maxTileX - minTileX + 1)];
    int tileIndexOffset = 0;

    for(int ty = minTileY; ty <= maxTileY; ++ty) {
        for(int tx = minTileX; tx <= maxTileX; ++tx) {
            tileIndices[tileIndexOffset++] = new Point(tx, ty);
        }
    }

    return tileIndices;
}
 
Example 2
Source File: OrbitImageBioformats.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public BufferedImage getThumbnail() {
  //  if (true) return new BufferedImage(100,60,BufferedImage.TYPE_INT_RGB);
     long thumbW=1;
     long thumbH=1;

    try {
        IFormatReader ir = getIFormatReader(reader.get().getCurrentFile(),null);
        ir.setId(reader.get().getCurrentFile());
        ir.setSeries(reader.get().getSeries());

        //int lev = numLevels-1;
        for (int lev=numLevels-1; lev>=0; lev--)
        {
            ir.setResolution(lev);
            thumbW = ir.getSizeX();
            thumbH = ir.getSizeY();
            double diff = Math.abs((thumbW/(double)thumbH) - (width/(double)height));
            logger.trace("thumb lev: "+lev+"  diff: "+diff+"  WxH: "+thumbW+"x"+thumbH);
            if (diff< THUMBNAIL_RATIO_DIFF) break; // 0.001
        }

        BufferedImageReader bir = BufferedImageReader.makeBufferedImageReader(ir);
        BufferedImage thumb = bir.openImage(0);
        bir.close();

        if (thumbW>maxThumbWidth) {
            int h = (int)(maxThumbWidth * (thumbH/(double)thumbW));
            BufferedImage img = new BufferedImage(maxThumbWidth,h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = (Graphics2D) img.getGraphics();
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g2d.drawImage(thumb,0,0,maxThumbWidth,h, null);
            thumb = img;
        }
        return thumb;
    } catch (IOException | FormatException e) {
        e.printStackTrace();
    }
    return null;
}