Package org.geotools.image

Examples of org.geotools.image.ImageWorker


     * since sometimes I get some problems with JAI encoders I select only
     * the first band, which by the way is the only band we use.
     */
    RenderedImage image = (sourceCoverage).geophysics(false)
        .getRenderedImage();
    final ImageWorker worker = new ImageWorker(image);

    // /////////////////////////////////////////////////////////////////////
    //
    // With index color model we want just the first band
    //
    // /////////////////////////////////////////////////////////////////////
    if (image.getColorModel() instanceof IndexColorModel
        && (image.getSampleModel().getNumBands() > 1)) {
      worker.retainBands(1);
      image = worker.getRenderedImage();
    }

    /**
     * For the moment we do not work with DirectColorModel but instead we
     * switch to component color model which is really easier to handle even
     * if it much more memory expensive. Once we are in component color
     * model is really easy to go to Gif and similar.
     */
    if (image.getColorModel() instanceof DirectColorModel) {
      worker.forceComponentColorModel();
      image = worker.getRenderedImage();
    }

    /**
     * ADJUSTMENTS FOR VARIOUS FILE FORMATS
     */

    // ------------------------GIF-----------------------------------
    if (extension.compareToIgnoreCase("gif") == 0) {

      /**
       * IndexColorModel with more than 8 bits for sample might be a
       * problem because GIF allows only 8 bits based palette therefore I
       * prefere switching to component color model in order to handle
       * this properly. NOTE. The only transfert types avalaible for
       * IndexColorModel are byte and ushort.
       */
      if (image.getColorModel() instanceof IndexColorModel
          && (image.getSampleModel().getTransferType() != DataBuffer.TYPE_BYTE)) {
        worker.forceComponentColorModel();
        image = worker.getRenderedImage();
      }

      /**
       * component color model is not well digested by the gif encoder we
       * need to go to indecolor model somehow. This code for the moment
       * remove transparency, but I am confident I will find a way to add
       * that.
       */
      if (image.getColorModel() instanceof ComponentColorModel) {
        worker.forceIndexColorModelForGIF(true);
        image = worker.getRenderedImage();
      } else
      /**
       * IndexColorModel with full transparency support is not suitable
       * for gif images we need to go to bitmask loosing some
       * informations. we have only one full transparent color.
       */
      if (image.getColorModel() instanceof IndexColorModel) {
        worker.forceIndexColorModelForGIF(true);
        image = worker.getRenderedImage();
      }
    }
    // else
    // -----------------TIFF--------------------------------------

View Full Code Here


                if (!(extender != null && extender instanceof BorderExtender)) {
                    localHints.add(ImageUtilities.EXTEND_BORDER_BY_COPYING);
                }
            }

            ImageWorker iw = new ImageWorker(image);
            iw.setRenderingHints(localHints);
            iw.affine(targetWorldToGrid, request.getInterpolation(), DEFAULT_BACKGROUND_VALUES);
            image = iw.getRenderedImage();
        }
        return image;
    }
View Full Code Here

            // border extender
            if (addBorderExtender) {
                localHints.add(ImageUtilities.BORDER_EXTENDER_HINTS);
            }

            ImageWorker iw = new ImageWorker(raster);
            iw.setRenderingHints(localHints);
            iw.affine(finalRaster2Model, interpolation, DEFAULT_BACKGROUND_VALUES);
            return iw.getRenderedImage();

        } catch (IllegalStateException e) {
            if (LOGGER.isLoggable(java.util.logging.Level.WARNING)) {
                LOGGER.log(java.util.logging.Level.WARNING,
                        new StringBuilder("Unable to load raster for granuleDescriptor ")
View Full Code Here

        ////
        RenderedImage initialImage;
        if(type!=null&&type.equalsIgnoreCase("HISTOGRAM"))
        {
          initialImage =
            new ImageWorker(sourceImage)
              .setRenderingHints(hints)
              .forceComponentColorModel()
              .rescaleToBytes()
              .getRenderedImage();
        }
        else
        {
          initialImage =
            new ImageWorker(sourceImage)
              .setRenderingHints(hints)
              .forceComponentColorModel()
              .getRenderedImage();
        }
        final int numbands = initialImage.getSampleModel().getNumBands();


        // //
        //
        // Save the alpha band if present, in order to put it back
        // later in the loop. We are not going to use it anyway for
        // the IHS conversion.
        //
        // //
        RenderedImage alphaBand = null;
        if (numbands % 2 == 0) {
          // get the alpha band
          alphaBand = new ImageWorker(initialImage)
              .setRenderingHints(hints).retainLastBand()
              .getRenderedImage();
          // strip the alpha band from the original image
          initialImage = new ImageWorker(initialImage)
              .setRenderingHints(hints).retainBands(numbands - 1)
              .getRenderedImage();
        }

        // //
        //
        // Get the single band to work on, which might be the
        // intensity for RGB(A) or the GRAY channel for Gray(A)
        //
        // //
        RenderedImage intensityImage = null;
        RenderedImage hChannel = null;
        RenderedImage sChannel = null;
        final boolean intensity;
        RenderedImage IHS = null;
        if (numbands > 1) {
          // convert the prepared image to IHS colorspace to work
          // on I band
          IHS = new ImageWorker(initialImage)
              .setRenderingHints(hints).forceColorSpaceIHS()
              .getRenderedImage();

          // get the various singular bands
          intensityImage = new ImageWorker(IHS).setRenderingHints(
              hints).retainFirstBand().getRenderedImage();
          sChannel = new ImageWorker(IHS).setRenderingHints(hints)
              .retainLastBand().getRenderedImage();
          hChannel = new ImageWorker(IHS).setRenderingHints(hints)
              .retainBands(new int[] { 1 }).getRenderedImage();
          intensity = true;
        } else {
          // //
          //
          // we have only one band we don't need to go to IHS
          //
          // //
          intensityImage = initialImage;
          intensity = false;
        }

        // /////////////////////////////////////////////////////////////////////
        //
        // HISTOGRAM ENHANCEMENT
        //
        //
        //
        // /////////////////////////////////////////////////////////////////////
        final RenderedImage heImage = performContrastEnhancement(intensityImage, hints);
         

        // /////////////////////////////////////////////////////////////////////
        //
        // GAMMA CORRECTION
        //
        // Lookup for building the actual lut that caches the gamma
        // correction function's values.
        //
        // /////////////////////////////////////////////////////////////////////
        RenderedImage finalImage = performGammaCorrection(heImage,hints);

        // /////////////////////////////////////////////////////////////////////
        //
        // POSTPROCESSING
        //
        // Take care of the intermediated image we left back. This
        // means, handle the fact that we might have gone to IHS and
        // the alpha band.
        //
        // /////////////////////////////////////////////////////////////////////
        if (intensity) {

          // //
          //
          // IHS --> RGB
          //
          // Let's merge the modified IHS image. The message on
          // the mailing list (see comments for this class)
          // mentioned that it is required to pass a RenderingHing
          // with a ImageLayout with the IHS color
          // model.
          //
          // //
          final ImageLayout imageLayout = new ImageLayout();
          imageLayout.setColorModel(IHS.getColorModel());
          imageLayout.setSampleModel(IHS.getSampleModel());
          final RenderingHints rendHints = new RenderingHints(Collections.EMPTY_MAP);
          rendHints.add(hints);
          rendHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT,imageLayout));
         
          // merge and go to rgb again
          final ParameterBlock pb = new ParameterBlock();
          pb.addSource(finalImage);
          pb.addSource(hChannel);
          pb.addSource(sChannel);
          finalImage = JAI.create("bandmerge", pb, rendHints);
          finalImage = new ImageWorker(finalImage).setRenderingHints(hints).forceColorSpaceRGB().getRenderedImage();

        }

        // //
        //
        // ALPHA BAND
        //
        // Let's merge the alpha band with the image we have rebuilt.
        //
        // //
        if (alphaBand != null) {
          final ColorModel cm = new ComponentColorModel(
              numbands >= 3 ? ColorSpace
                  .getInstance(ColorSpace.CS_sRGB)
                  : ColorSpace
                      .getInstance(ColorSpace.CS_GRAY),
              numbands >= 3 ? new int[] { 8, 8, 8, 8 }
                  : new int[] { 8, 8 }, true, false,
              Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
          final ImageLayout imageLayout = new ImageLayout();
          imageLayout.setColorModel(cm);
          imageLayout.setSampleModel(cm.createCompatibleSampleModel(finalImage.getWidth(), finalImage.getHeight()));
          // merge and go to rgb
          finalImage =
            new ImageWorker(finalImage)
              .setRenderingHints(hints)
              .setRenderingHint(JAI.KEY_IMAGE_LAYOUT,imageLayout)
              .addBand(alphaBand, false)
              .getRenderedOperation();
View Full Code Here

        // IT WORKS ONLY ON BYTE DATA TYPE!!!
        //
        // /////////////////////////////////////////////////////////////////////

        //convert the input image to 8 bit
        inputImage=new ImageWorker(inputImage).rescaleToBytes().getRenderedImage();
        // compute the histogram
        final RenderedOp hist = HistogramDescriptor.create(inputImage,
            null, Integer.valueOf(1), Integer.valueOf(1),
            new int[] { 256 }, new double[] { 0 },
            new double[] { 256 }, null);
View Full Code Here

                return null;
        }

        RenderedImage im=null;
        try {
            ImageWorker iw = new ImageWorker(finalImage);
            iw.setRenderingHints(hints);
            iw.affine(finalRasterTransformation, interpolation, bkgValues);
            im = iw.getRenderedImage();
        } finally {
                if(DEBUG){
                    writeRenderedImage(im, "postAffine");
                }
        }       
View Full Code Here

                // /////////////////////////////////////////////////////////////
                if (t instanceof IllegalArgumentException) {
                    if (DEBUG) {
                        writeRenderedImage(finalImage, "preWORKAROUND1");
                    }
                    final RenderedImage image = new ImageWorker(finalImage)
                            .forceComponentColorModel(true).getRenderedImage();

                    if (DEBUG) {
                        writeRenderedImage(image, "WORKAROUND1");
View Full Code Here

    if(numBands>4)
    {
      //get the visible band
      final int visibleBand=CoverageUtilities.getVisibleBand(outputImage);
      outputImage=
        new ImageWorker(outputImage).setRenderingHints(this.getHints()).retainBands(new int[]{visibleBand}).getRenderedImage();
      sd=new GridSampleDimension[]{(GridSampleDimension) output.getSampleDimension(visibleBand)};
    }else{
        sd=output.getSampleDimensions();
    }

    //more general case, let's check the data type and let go only USHORT and BYTE
    // TODO I am not sure this will work with multipacked types (using INT for an RGB as an instance)
    // TODO should we go to component color model also?
    // TODO use JAI TOOLS statistics and ignore no data properly.
    switch(dataType){
      // in case the original image has a USHORT pixel type without being associated
      // with an index color model I would still go to 8 bits
      case DataBuffer.TYPE_USHORT:
        if(outputImage.getColorModel() instanceof IndexColorModel){
          break;
        }
      case DataBuffer.TYPE_DOUBLE:
      case DataBuffer.TYPE_FLOAT:
      case DataBuffer.TYPE_INT:
      case DataBuffer.TYPE_SHORT:
      //rescale to byte
      outputImage=
        new ImageWorker(outputImage).setRenderingHints(this.getHints()).rescaleToBytes().getRenderedImage();
       
    }
   
          // ///////////////////////////////////////////////////////////////////
          // Apply opacity if needed
          // ///////////////////////////////////////////////////////////////////
          final RenderedImage finalImage;
          if(opacity < 1) {
              ImageWorker ow = new ImageWorker(outputImage);
              finalImage = ow.applyOpacity(opacity).getRenderedImage();
             
              numBands=finalImage.getSampleModel().getNumBands();
              sd= new GridSampleDimension[numBands];
              for(int i=0;i<numBands;i++) {
                  sd[i]= new GridSampleDimension(TypeMap.getColorInterpretation(finalImage.getColorModel(), i).name());
View Full Code Here

        // /////////////////////////////////////////////////////////////////////
        //
        //
        //
        // /////////////////////////////////////////////////////////////////////
        final RenderedImage image = new ImageWorker(JAI.create("ImageRead", TestData.file(this,
            "usa.png"))).forceComponentColorModel().retainFirstBand().getRenderedImage();
        if (TestData.isInteractiveTest())
            ImageIOUtilities.visualize(image, "testLookupByte");
   
        // /////////////////////////////////////////////////////////////////////
View Full Code Here

      //
      // /////////////////////////////////////////////////////////////////////
      final RenderedImage image = getSWAN();
      if (TestData.isInteractiveTest())
          ImageIOUtilities.visualize(image, "testSWANLOGARITHMIC");
      final RenderedOp statistics = ExtremaDescriptor.create(image, new ROI(new ImageWorker(image).binarize(0).getRenderedImage()),
          new Integer(1), new Integer(1), Boolean.FALSE, new Integer(1),
          null);
      final double[] minimum=(double[]) statistics.getProperty("minimum");
      final double[] maximum=(double[]) statistics.getProperty("maximum");
     
View Full Code Here

TOP

Related Classes of org.geotools.image.ImageWorker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.