Search in sources :

Example 1 with RenderedOp

use of javax.media.jai.RenderedOp in project vcell by virtualcell.

the class FRAPData method erodeDilate.

private UShortImage erodeDilate(UShortImage source, KernelJAI dilateErodeKernel, UShortImage mask, boolean bErode) throws ImageException {
    PlanarImage completedImage = null;
    PlanarImage operatedImage = null;
    PlanarImage planarSource = binarize(source);
    Integer borderPad = dilateErodeKernel.getWidth() / 2;
    planarSource = BorderDescriptor.create(planarSource, borderPad, borderPad, borderPad, borderPad, BorderExtender.createInstance(BorderExtender.BORDER_ZERO), null).createInstance();
    if (bErode) {
        planarSource = AddConstDescriptor.create(planarSource, new double[] { 1.0 }, null).createInstance();
        RenderedOp erodeOP = ErodeDescriptor.create(planarSource, dilateErodeKernel, null);
        operatedImage = erodeOP.createInstance();
    } else {
        RenderedOp dilationOP = DilateDescriptor.create(planarSource, dilateErodeKernel, null);
        operatedImage = dilationOP.createInstance();
    }
    operatedImage = CropDescriptor.create(operatedImage, new Float(0), new Float(0), new Float(source.getNumX()), new Float(source.getNumY()), null);
    operatedImage = binarize(operatedImage.getAsBufferedImage());
    if (mask != null) {
        RenderedOp andDescriptor = AndDescriptor.create(operatedImage, binarize(mask), null);
        completedImage = andDescriptor.createInstance();
    } else {
        completedImage = operatedImage;
    }
    return convertToUShortImage(completedImage, source.getOrigin(), source.getExtent());
}
Also used : RenderedOp(javax.media.jai.RenderedOp) PlanarImage(javax.media.jai.PlanarImage)

Example 2 with RenderedOp

use of javax.media.jai.RenderedOp in project vcell by virtualcell.

the class UShortImage method erodeDilate.

public static UShortImage erodeDilate(UShortImage source, KernelJAI dilateErodeKernel, UShortImage mask, boolean bErode) throws ImageException {
    PlanarImage completedImage = null;
    PlanarImage operatedImage = null;
    PlanarImage planarSource = binarize(source);
    Integer borderPad = dilateErodeKernel.getWidth() / 2;
    planarSource = BorderDescriptor.create(planarSource, borderPad, borderPad, borderPad, borderPad, BorderExtender.createInstance(BorderExtender.BORDER_ZERO), null).createInstance();
    if (bErode) {
        planarSource = AddConstDescriptor.create(planarSource, new double[] { 1.0 }, null).createInstance();
        RenderedOp erodeOP = ErodeDescriptor.create(planarSource, dilateErodeKernel, null);
        operatedImage = erodeOP.createInstance();
    } else {
        RenderedOp dilationOP = DilateDescriptor.create(planarSource, dilateErodeKernel, null);
        operatedImage = dilationOP.createInstance();
    }
    operatedImage = CropDescriptor.create(operatedImage, new Float(0), new Float(0), new Float(source.getNumX()), new Float(source.getNumY()), null);
    operatedImage = binarize(operatedImage.getAsBufferedImage());
    if (mask != null) {
        RenderedOp andDescriptor = AndDescriptor.create(operatedImage, binarize(mask), null);
        completedImage = andDescriptor.createInstance();
    } else {
        completedImage = operatedImage;
    }
    return convertToUShortImage(completedImage, source.getOrigin(), source.getExtent());
}
Also used : RenderedOp(javax.media.jai.RenderedOp) PlanarImage(javax.media.jai.PlanarImage)

Example 3 with RenderedOp

use of javax.media.jai.RenderedOp in project imageio-ext by geosolutions-it.

the class TurboJpegImageWriter method refineImage.

/**
 * Performs a few check in order to make sure to provide the proper data bytes to the
 * incoming encoding phase. When calling getData(Rectangle).getDataBuffer() on an image having size
 * smaller than the tile size, the underlying data buffer will be made of the data contained in the
 * full tile (Even having used the getData(Rectangle) call. As an instance, a Rectangle(0,0,64,64)
 * extracted from a 64x64 image with tiling 128x128 will result into a ByteBuffer filled with
 * 128x128xBands bytes. (Therefore a lot of zeros). The encoded image will have a lot of scattered
 * black stripes.
 * This method do a copy of the only needed part of data when such a condition is met, or return the
 * original image otherwise.
 *
 * @param srcImage The source image to be refined.
 * @return
 */
private RenderedImage refineImage(RenderedImage srcImage) {
    final int w = srcImage.getWidth();
    final int h = srcImage.getHeight();
    final int minX = srcImage.getMinX();
    final int minY = srcImage.getMinY();
    final int tw = srcImage.getTileWidth();
    final int th = srcImage.getTileHeight();
    // portion of the original data
    if ((tw > w) || (th > h)) {
        RenderingHints hints = null;
        ImageLayout layout = null;
        if (srcImage instanceof RenderedOp) {
            hints = ((RenderedOp) srcImage).getRenderingHints();
            if ((hints != null) && hints.containsKey(JAI.KEY_IMAGE_LAYOUT)) {
                layout = (ImageLayout) hints.get(JAI.KEY_IMAGE_LAYOUT);
            } else {
                layout = new ImageLayout(srcImage);
            }
        } else {
            layout = new ImageLayout(srcImage);
            hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
        }
        // Imposing the layout of the requested image
        // as well as reducing the tile layout which was
        // bigger than the image
        layout.setTileHeight(h);
        layout.setTileWidth(w);
        layout.setTileGridXOffset(minX);
        layout.setTileGridYOffset(minY);
        layout.setMinX(minX);
        layout.setMinY(minY);
        layout.setWidth(w);
        layout.setHeight(h);
        srcImage = new CopyOpImage(srcImage, hints, layout);
    }
    return srcImage;
}
Also used : CopyOpImage(com.sun.media.jai.opimage.CopyOpImage) RenderedOp(javax.media.jai.RenderedOp) ImageLayout(javax.media.jai.ImageLayout) RenderingHints(java.awt.RenderingHints)

Example 4 with RenderedOp

use of javax.media.jai.RenderedOp in project imageio-ext by geosolutions-it.

the class JP2KWriteTest method write_Cprecincts.

// ////////////////////////////////////////////////////////////////////////
// 
// Testing "Cprecincts" Create Option.
// 
// ////////////////////////////////////////////////////////////////////////
@Test
public void write_Cprecincts() throws IOException, FileNotFoundException {
    if (!isJp2KakDriverAvailable)
        return;
    LOGGER.info("Testing JP2 Write operation with Cprecincts option setting");
    // //
    // Preparing input/output files
    // //
    final File inputFile = TestData.file(this, testFileName);
    Assert.assertTrue(inputFile.exists());
    // Output files resulting from 2 different values of the same create
    // option. In this test, the create option is Cprecincts.
    final File outputFile1 = TestData.temp(this, "CprecintsA-.jp2", deleteTempFilesOnExit);
    final File outputFile2 = TestData.temp(this, "CprecintsB-.jp2", deleteTempFilesOnExit);
    // //
    // Preparing to read
    // //
    final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", inputFile);
    if (ENABLE_SUBSAMPLING) {
        ImageReadParam readParam = new ImageReadParam();
        readParam.setSourceSubsampling(4, 4, 0, 0);
        pbjImageRead.setParameter("readParam", readParam);
    }
    pbjImageRead.setParameter("Reader", new JP2GDALKakaduImageReaderSpi().createReaderInstance());
    RenderedOp image = JAI.create("ImageRead", pbjImageRead);
    // ////////////////////////////////////////////////////////////////////
    // 
    // preparing to write (1ST version of the create option test)
    // 
    // ////////////////////////////////////////////////////////////////////
    // Setting output and writer
    final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
    pbjImageWrite.setParameter("Output", new FileImageOutputStreamExtImpl(outputFile1));
    ImageWriter writer = new JP2GDALKakaduImageWriterSpi().createWriterInstance();
    pbjImageWrite.setParameter("Writer", writer);
    // Specifying image source to write
    pbjImageWrite.addSource(image);
    ImageWriteParam param = writer.getDefaultWriteParam();
    // Specifying the required create option
    ((JP2GDALKakaduImageWriteParam) param).setCprecincts("{256,256},{256,256},{128,128}");
    pbjImageWrite.setParameter("writeParam", param);
    // Writing
    final RenderedOp op = JAI.create("ImageWrite", pbjImageWrite);
    // ////////////////////////////////////////////////////////////////////
    // 
    // preparing to write (2ND version of the create option test)
    // 
    // ////////////////////////////////////////////////////////////////////
    // Setting output and writer
    final ParameterBlockJAI pbjImageWrite2 = new ParameterBlockJAI("ImageWrite");
    pbjImageWrite2.setParameter("Output", new FileImageOutputStreamExtImpl(outputFile2));
    ImageWriter writer2 = new JP2GDALKakaduImageWriterSpi().createWriterInstance();
    pbjImageWrite2.setParameter("Writer", writer2);
    // Specifying image source to write
    pbjImageWrite2.addSource(image);
    ImageWriteParam param2 = writer2.getDefaultWriteParam();
    // Specifying the required create option
    ((JP2GDALKakaduImageWriteParam) param2).setCprecincts("{512,512},{256,512},{128,512},{64,512},{32,512},{16,512},{8,512},{4,512},{2,512}");
    pbjImageWrite2.setParameter("writeParam", param2);
    // Writing
    final RenderedOp op2 = JAI.create("ImageWrite", pbjImageWrite2);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) FileImageOutputStreamExtImpl(it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl) ImageWriteParam(javax.imageio.ImageWriteParam) File(java.io.File) Test(org.junit.Test)

Example 5 with RenderedOp

use of javax.media.jai.RenderedOp in project imageio-ext by geosolutions-it.

the class JP2KWriteTest method write_GeoJp2.

// ////////////////////////////////////////////////////////////////////////
// 
// Testing "GeoJp2" Create Option.
// 
// ////////////////////////////////////////////////////////////////////////
@Test
public void write_GeoJp2() throws IOException, FileNotFoundException {
    if (!isJp2KakDriverAvailable)
        return;
    LOGGER.info("Testing JP2 Write operation with GeoJp2 option setting");
    // //
    // Preparing input/output files
    // //
    final File inputFile = TestData.file(this, "bogota.jp2");
    Assert.assertTrue(inputFile.exists());
    // Output files resulting from 2 different values of the same create
    // option. In this test, the create option is GeoJp2.
    final File outputFile1 = TestData.temp(this, "GeoJp2-.jp2", deleteTempFilesOnExit);
    final File outputFile2 = TestData.temp(this, "NO-GeoJp2-.jp2", deleteTempFilesOnExit);
    // //
    // Preparing to read
    // //
    final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", inputFile);
    if (ENABLE_SUBSAMPLING) {
        ImageReadParam readParam = new ImageReadParam();
        readParam.setSourceSubsampling(4, 4, 0, 0);
        pbjImageRead.setParameter("readParam", readParam);
    }
    pbjImageRead.setParameter("Reader", new JP2GDALKakaduImageReaderSpi().createReaderInstance());
    RenderedOp image = JAI.create("ImageRead", pbjImageRead);
    // ////////////////////////////////////////////////////////////////////
    // 
    // preparing to write (1ST version of the create option test)
    // 
    // ////////////////////////////////////////////////////////////////////
    // Setting output and writer
    final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
    pbjImageWrite.setParameter("Output", new FileImageOutputStreamExtImpl(outputFile1));
    ImageWriter writer = new JP2GDALKakaduImageWriterSpi().createWriterInstance();
    pbjImageWrite.setParameter("Writer", writer);
    // Specifying image source to write
    pbjImageWrite.addSource(image);
    ImageWriteParam param = writer.getDefaultWriteParam();
    // Specifying the required create option
    ((JP2GDALKakaduImageWriteParam) param).setGeoJp2("YES");
    pbjImageWrite.setParameter("writeParam", param);
    // Writing
    final RenderedOp op = JAI.create("ImageWrite", pbjImageWrite);
    // ////////////////////////////////////////////////////////////////////
    // 
    // preparing to write (2ND version of the create option test)
    // 
    // ////////////////////////////////////////////////////////////////////
    // Setting output and writer
    final ParameterBlockJAI pbjImageWrite2 = new ParameterBlockJAI("ImageWrite");
    pbjImageWrite2.setParameter("Output", new FileImageOutputStreamExtImpl(outputFile2));
    ImageWriter writer2 = new JP2GDALKakaduImageWriterSpi().createWriterInstance();
    pbjImageWrite2.setParameter("Writer", writer2);
    // Specifying image source to write
    pbjImageWrite2.addSource(image);
    ImageWriteParam param2 = writer2.getDefaultWriteParam();
    // Specifying the required create option
    ((JP2GDALKakaduImageWriteParam) param2).setGeoJp2("NO");
    pbjImageWrite2.setParameter("writeParam", param2);
    // Writing
    final RenderedOp op2 = JAI.create("ImageWrite", pbjImageWrite2);
}
Also used : ImageReadParam(javax.imageio.ImageReadParam) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) FileImageOutputStreamExtImpl(it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl) ImageWriteParam(javax.imageio.ImageWriteParam) File(java.io.File) Test(org.junit.Test)

Aggregations

RenderedOp (javax.media.jai.RenderedOp)82 File (java.io.File)72 ParameterBlockJAI (javax.media.jai.ParameterBlockJAI)71 Test (org.junit.Test)61 ImageReadParam (javax.imageio.ImageReadParam)48 AbstractGDALTest (it.geosolutions.imageio.gdalframework.AbstractGDALTest)32 ImageWriter (javax.imageio.ImageWriter)28 ImageLayout (javax.media.jai.ImageLayout)28 ImageWriteParam (javax.imageio.ImageWriteParam)23 RenderingHints (java.awt.RenderingHints)21 FileImageOutputStreamExtImpl (it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl)20 ImageReader (javax.imageio.ImageReader)14 FileNotFoundException (java.io.FileNotFoundException)13 Rectangle (java.awt.Rectangle)9 IIOMetadata (javax.imageio.metadata.IIOMetadata)5 IOException (java.io.IOException)4 ImageInputStream (javax.imageio.stream.ImageInputStream)4 FileImageInputStreamExtImpl (it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl)3 ColorSpace (java.awt.color.ColorSpace)3 ColorModel (java.awt.image.ColorModel)3