Search in sources :

Example 1 with FileOpener

use of ij.io.FileOpener in project TrakEM2 by trakem2.

the class Patch method getAlphaMask.

/**
 * Return a new {@link ByteProcessor} representing the alpha mask, if any, over the pixel data.
 * @return null if there isn't one, or if the mask image could not be loaded.
 */
public synchronized ByteProcessor getAlphaMask() {
    if (0 == alpha_mask_id)
        return null;
    final String path = createAlphaMaskFilePath(alpha_mask_id);
    // Expects a zip file containing one single TIFF file entry
    ZipInputStream zis = null;
    try {
        zis = new ZipInputStream(new FileInputStream(path));
        // prepares the entry for reading
        final ZipEntry ze = zis.getNextEntry();
        // Assume the first entry is the mask
        final ImageProcessor mask = new FileOpener(new TiffDecoder(zis, ze.getName()).getTiffInfo()[0]).open(false).getProcessor();
        if (mask.getWidth() != o_width || mask.getHeight() != o_height) {
            Utils.log2("Mask has improper dimensions: " + mask.getWidth() + " x " + mask.getHeight() + " for patch #" + this.id + " which is of " + o_width + " x " + o_height);
            return null;
        }
        return (ByteProcessor) (mask.getClass() == ByteProcessor.class ? mask : mask.convertToByte(false));
    } catch (final Throwable t) {
        Utils.log2("Could not load alpha mask for patch #" + this.id + " from file " + path);
        IJError.print(t);
        return null;
    } finally {
        try {
            if (null != zis)
                zis.close();
        } catch (final Exception e) {
            IJError.print(e);
        }
    }
}
Also used : FileOpener(ij.io.FileOpener) ByteProcessor(ij.process.ByteProcessor) ImageProcessor(ij.process.ImageProcessor) TiffDecoder(ij.io.TiffDecoder) ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) FileInputStream(java.io.FileInputStream) NoninvertibleModelException(mpicbg.models.NoninvertibleModelException) NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) IOException(java.io.IOException)

Aggregations

FileOpener (ij.io.FileOpener)1 TiffDecoder (ij.io.TiffDecoder)1 ByteProcessor (ij.process.ByteProcessor)1 ImageProcessor (ij.process.ImageProcessor)1 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 NoninvertibleModelException (mpicbg.models.NoninvertibleModelException)1