loci.formats.FormatException Java Examples

The following examples show how to use loci.formats.FormatException. 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: OrbitImageBioformats.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
@Deprecated
private int getRealResolutionCount(IFormatReader imageReader) throws IOException, FormatException {
    ImageReader ir = new ImageReader();
    ir.setFlattenedResolutions(false);
    ir.setId(imageReader.getCurrentFile());
    ir.setSeries(imageReader.getSeries());
    int numRes = 1;
    for (int lev=imageReader.getResolutionCount()-1; lev>=0; lev--) {
        numRes = lev;
        ir.setResolution(lev);
        int thumbW = ir.getSizeX();
        int thumbH = ir.getSizeY();
        double diff = Math.abs((thumbW/(double)thumbH) - (imageReader.getSizeX()/(double)imageReader.getSizeY()));
        System.out.println("diff: "+diff);
        if (diff<0.001) break;
    }
    ir.close();
    return numRes;
}
 
Example #2
Source File: MultiplexImageReader.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BufferedImage openImage(int no, int x, int y, int w, int h) throws FormatException, IOException {
    int[] zct = getZCTCoords(no);
    int z = zct[0];
    int chan = zct[1];
    int t = zct[2];
    RectZT rect = new RectZT(x,y,w,h,z,t);
    if (currentRect==null || !currentRect.equals(rect)) {
        logger.trace("cache failed - loading");
        openUnmixedImages(no,x,y,w,h); // unmix all channels at once
    }
    return unmixedChannels[chan];
}
 
Example #3
Source File: TiffConverter.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public static int getNumPagesInZVI(String filename) throws IOException, FormatException {

        ImageProcessorReader r = new ImageProcessorReader(
                new ChannelSeparator(new ZeissZVIReader())); // LociPrefs.makeImageReader()
        r.setId(filename);
        int num = r.getImageCount();
        //int width = r.getSizeX();
        //int height = r.getSizeY();
        // howto color conversion: http://trac.openmicroscopy.org.uk/ome/browser/bioformats.git/components/loci-plugins/utils/Read_Image.java
        r.close();
        return num;
    }
 
Example #4
Source File: TiffConverter.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public static int getNumPagesInLIF(String filename) throws IOException, FormatException {

        ImageProcessorReader r = new ImageProcessorReader(
                new ChannelSeparator(new LIFReader()));
        r.setId(filename);
        int num = r.getImageCount();
        r.close();
        return num;
    }
 
Example #5
Source File: TiffConverter.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public static PlanarImage getZVIPage(String filename, int num) throws IOException, FormatException {
    ImageProcessorReader r = new ImageProcessorReader(
            new ChannelSeparator(new ZeissZVIReader())); // LociPrefs.makeImageReader()
    r.setId(filename);
    ImageProcessor ip = r.openProcessors(num)[0]; // (page)[0]
    return PlanarImage.wrapRenderedImage(ip.getBufferedImage());
}
 
Example #6
Source File: TiffConverter.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public static PlanarImage getLIFPage(String filename, int num) throws IOException, FormatException {
    ImageProcessorReader r = new ImageProcessorReader(
            new ChannelSeparator(new LIFReader()));
    r.setId(filename);
    ImageProcessor ip = r.openProcessors(num)[0]; // (page)[0]
    return PlanarImage.wrapRenderedImage(ip.getBufferedImage());
}
 
Example #7
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;
}
 
Example #8
Source File: MultiplexImageReader.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
public BufferedImage[] openUnmixedImages(int no, int x, int y, int w, int h) throws FormatException, IOException {
    int[] zct = getZCTCoords(no);
    int z = zct[0];
    int chan = zct[1];
    int t = zct[2];
    // load all channels for current rect
    BufferedImage[] channels = new BufferedImage[sizeC];
    for (int c=0; c<sizeC; c++) {
        int no2 = getIndex(z,c,t);
        channels[c] = super.openImage(no2,x,y,w,h);
    }

    BufferedImage ori = channels[0];
    BufferedImage[] bi = new BufferedImage[sizeC];
    WritableRaster[] raster = new WritableRaster[sizeC];
    for (int c=0; c<sizeC; c++) {
        if (!channelIndependent[c]) {
            bi[c] = new BufferedImage(ori.getColorModel(), ori.getRaster().createCompatibleWritableRaster(0, 0, w, h), ori.isAlphaPremultiplied(), null);
            raster[c] = bi[c].getRaster();
        } else {
            bi[c] = channels[c];   // original image, independent channel
            raster[c] = bi[c].getRaster();
        }
    }
    double[] measurements = new double[sizeDependend];
    double[] out = new double[sizeDependend];
    for (int ix=ori.getMinX(); ix<ori.getMinX()+ori.getWidth(); ix++)
        for (int iy=ori.getMinY(); iy<ori.getMinY()+ori.getHeight(); iy++) {
            for (int c=0; c<sizeDependend; c++) {
                measurements[c] = channels[channelMap[c]].getRaster().getSampleDouble(ix,iy,0); // only 1 banded rasters allowed here
            }
            fastMultiply(invMatrix,measurements,out);   // here the real unmixing takes place
            for (int c=0; c<sizeDependend; c++) {
                if (out[c]>255) out[c] = 255d;        // TODO: adjust for 16bit!!!
                if (out[c]<0) out[c] = 0d;
                raster[channelMap[c]].setSample(ix, iy, 0, out[c]);
            }
        }
    unmixedChannels = bi;
    currentRect = new RectZT(x,y,w,h,z,t);

    return bi;
}
 
Example #9
Source File: NDPIUtils.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws IOException, FormatException {
    NDPISReaderOrbit r = new NDPISReaderOrbit();
    r.setId("D:\\pic\\Hamamatsu\\Scan_Manuel\\Staining-DAPI-Cy5.5-FITC-scan all channels fix.ndpis");
    System.out.println(Arrays.toString(getExposureTimesGain(r)));
    r.close();
}