javax.media.jai.ImageLayout Java Examples

The following examples show how to use javax.media.jai.ImageLayout. 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: GeoWaveRasterReader.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public ImageLayout getImageLayout(final String coverageName) throws IOException {
  if (!checkName(coverageName)) {
    LOGGER.warn("Unable to find data adapter for '" + coverageName + "'");
    return null;
  }

  final RasterDataAdapter adapter =
      (RasterDataAdapter) geowaveAdapterStore.getAdapter(getAdapterId(coverageName));
  final GridEnvelope gridEnvelope = getOriginalGridRange();
  return new ImageLayout().setMinX(gridEnvelope.getLow(0)).setMinY(
      gridEnvelope.getLow(1)).setTileWidth(adapter.getTileSize()).setTileHeight(
          adapter.getTileSize()).setSampleModel(adapter.getSampleModel()).setColorModel(
              adapter.getColorModel()).setWidth(gridEnvelope.getHigh(0)).setHeight(
                  gridEnvelope.getHigh(1));
}
 
Example #2
Source File: WarpOpImage.java    From geowave with Apache License 2.0 6 votes vote down vote up
public WarpOpImage(
    final RenderedImage source,
    final ImageLayout layout,
    final Map<?, ?> configuration,
    final boolean cobbleSources,
    final BorderExtender extender,
    final Interpolation interp,
    final Warp warp,
    final double[] backgroundValues,
    final ROI roi,
    final Range noData) {
  super(
      source,
      layout,
      configuration,
      cobbleSources,
      extender,
      interp,
      warp,
      backgroundValues,
      roi,
      noData);
}
 
Example #3
Source File: BinarizeDescriptor.java    From pdfxtk with Apache License 2.0 6 votes vote down vote up
/** Creates an BinarizeOpImage with a given ParameterBlock */

  public RenderedImage create(ParameterBlock paramBlock, 
			      RenderingHints renderingHints)
  {
    RenderedImage img = paramBlock.getRenderedSource(0);

    ImageLayout il = new ImageLayout(img);
    ColorModel cm = new IndexColorModel(1, 2, bwColors, bwColors, bwColors);
    SampleModel sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
						     img.getWidth(),
						     img.getHeight(),
						     1);

    il.setColorModel(cm);
    il.setSampleModel(sm);

    return new BinarizeOpImage(paramBlock.getRenderedSource(0),
			       renderingHints,
			       il,
			       (Integer)paramBlock.getObjectParameter(0));
  }
 
Example #4
Source File: SkeletonDescriptor.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Creates an RLSAOpImage with a given ParameterBlock */

  public RenderedImage create(ParameterBlock paramBlock, 
			      RenderingHints renderingHints)
  {
    return new SkeletonOpImage(paramBlock.getRenderedSource(0),
			       renderingHints,
			       new ImageLayout(paramBlock.getRenderedSource(0)),
			       (Boolean) paramBlock.getObjectParameter(0));
  }
 
Example #5
Source File: RandomizeDescriptor.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Creates an RandomizeOpImage with a given ParameterBlock */

  public RenderedImage create(ParameterBlock paramBlock, 
			      RenderingHints renderingHints)
  {
    int width = ((Integer) paramBlock.getObjectParameter(0)).intValue();
    int height = ((Integer) paramBlock.getObjectParameter(1)).intValue();

    ImageLayout il = new ImageLayout(0, 0, width, height);

    int[] bits = { 8 };

    ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY),
					    bits, false, false,
					    Transparency.OPAQUE,
					    DataBuffer.TYPE_BYTE);

    int[] bandoffsets = { 0 };
    
    SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
					      width, height, 1, width,
					      bandoffsets);


    il.setColorModel(cm);
    il.setSampleModel(sm);

    return new RandomizeOpImage(il, renderingHints, (Double) paramBlock.getObjectParameter(2));
  }
 
Example #6
Source File: RandomizeOpImage.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Constructs a RandomizeOpImage object */

  public RandomizeOpImage(ImageLayout layout,
			  Map configuration,
			  Double density)
  {
    super((Vector) null, layout, configuration, false);

    this.density = density.doubleValue();
  }
 
Example #7
Source File: RLSADescriptor.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Creates an RLSAOpImage with a given ParameterBlock */

  public RenderedImage create(ParameterBlock paramBlock, 
			      RenderingHints renderHints)
  {
    return new RLSAOpImage(paramBlock.getRenderedSource(0),
			   null,
			   new ImageLayout(paramBlock.getRenderedSource(0)),
			   (Integer) paramBlock.getObjectParameter(0),
			   (Integer) paramBlock.getObjectParameter(1));
  }
 
Example #8
Source File: RLSAOpImage.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Constructs an RLSAOpImage */

  public RLSAOpImage(RenderedImage source, 
		     Map hints,
		     ImageLayout layout,
		     Integer direction,
		     Integer threshold)
  {
    super(source, hints, layout);

    this.direction = direction.intValue();
    this.threshold = threshold.intValue();
  }
 
Example #9
Source File: BlackOrOpImage.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Constructs a BlackOrOpImage object */

  public BlackOrOpImage(RenderedImage source1,
			RenderedImage source2,
			ImageLayout layout,
			Map configuration,
			boolean cobbleSources)
  {
    super(source1, source2, layout, configuration, cobbleSources);
  }
 
Example #10
Source File: PowerOpImage.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Constructs a PowwerOpImage object */

  public PowerOpImage(RenderedImage source,
		      Map hints,
		      ImageLayout layout,
		      Double exponent)
  {
    super(source, hints, layout);

    this.exponent = exponent.doubleValue();
  }
 
Example #11
Source File: PowerDescriptor.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Creates an PowerOpImage with a given ParameterBlock */

  public RenderedImage create(ParameterBlock paramBlock, 
			      RenderingHints renderingHints)
  {
    return new PowerOpImage(paramBlock.getRenderedSource(0),
			    renderingHints,
			    new ImageLayout(paramBlock.getRenderedSource(0)),
			    (Double) paramBlock.getObjectParameter(0));
  }
 
Example #12
Source File: BinarizeOpImage.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Constructs a BinarizeOpImage object */

  public BinarizeOpImage(RenderedImage source,
			 Map hints,
			 ImageLayout layout,
			 Integer threshold)
  {
    super(source, hints, layout);

    this.threshold = threshold.intValue();
  }
 
Example #13
Source File: BlackOrDescriptor.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Creates a BlackOrOpImage with a given ParameterBlock */

  public RenderedImage create(ParameterBlock paramBlock, 
			      RenderingHints renderingHints)
  {
    return new BlackOrOpImage(paramBlock.getRenderedSource(0),
			      paramBlock.getRenderedSource(1),
			      new ImageLayout(paramBlock.getRenderedSource(0)),
			      renderingHints,
			      true);
  }
 
Example #14
Source File: SkeletonOpImage.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** Constructs a SkeletonOpImage object */

  public SkeletonOpImage(RenderedImage source,
			 Map configuration,
			 ImageLayout layout,
			 Boolean invert)
  {
    super(source, configuration, layout);

    this.invert = invert.booleanValue();
  }
 
Example #15
Source File: WarpRIF.java    From geowave with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of warp operator according to the warp object and interpolation method.
 *
 * @param paramBlock The warp and interpolation objects.
 */
@Override
public RenderedImage create(final ParameterBlock paramBlock, final RenderingHints renderHints) {
  final Interpolation interp = (Interpolation) paramBlock.getObjectParameter(1);
  if ((interp instanceof InterpolationNearest)
      || (interp instanceof javax.media.jai.InterpolationNearest)) {
    // Get ImageLayout from renderHints if any.
    final ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);

    RenderedImage source = paramBlock.getRenderedSource(0);
    final Warp warp = (Warp) paramBlock.getObjectParameter(0);
    final double[] backgroundValues = (double[]) paramBlock.getObjectParameter(2);

    ROI roi = null;
    final Object roi_ = paramBlock.getObjectParameter(3);
    if (roi_ instanceof ROI) {
      roi = (ROI) roi_;
      final PlanarImage temp = PlanarImage.wrapRenderedImage(source);
      temp.setProperty("ROI", roi);
      source = temp;
    }
    Range noData = (Range) paramBlock.getObjectParameter(4);
    noData = RangeFactory.convert(noData, source.getSampleModel().getDataType());
    return new WarpNearestOpImage(
        source,
        renderHints,
        layout,
        warp,
        interp,
        roi,
        noData,
        backgroundValues);
  }
  return super.create(paramBlock, renderHints);
}
 
Example #16
Source File: QuicklookOlciRIF.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new instance of <code>QuicklookOlciOpImage</code> in the 
 * rendered layer. This operator could be called by chunks of images.
 * A set of additional information are required to compute the pixels 
 * adjustment such as sun azimuth/elevation and detectors... The methods to
 * extract these informations are also provided here before. 
 * 
 * @param paramBlock The three R/G/B sources images to be "Merged" together
 * to produce the Quicklook.
 * @param renderHints Optionally contains destination image layout.
 */
public RenderedImage create(ParameterBlock paramBlock, RenderingHints hints)
{
// Get ImageLayout from renderHints if any.
   ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
   // Get the number of the sources
   int numSources = paramBlock.getNumSources();
   // Creation of a source ArrayList (better than a Vector)
   List<RenderedImage> sources = new ArrayList<RenderedImage>(numSources);

   // Addition of the sources to the List
   for (int i = 0; i < numSources; i++)
   {
      sources.add((RenderedImage)paramBlock.getSource(i));
   }
   
   // Extracts parameters
   short[][]  detectors = (short[][])paramBlock.getObjectParameter(0);
   double[][] sza = (double[][])paramBlock.getObjectParameter(1);
   float[][]  solar_flux = (float[][])paramBlock.getObjectParameter(2);
   PixelCorrection[]pc=(PixelCorrection[])paramBlock.getObjectParameter(3);
   int[]  bands = (int[])paramBlock.getObjectParameter(4);
   int[]  coefficients = (int[])paramBlock.getObjectParameter(5);
  
   return new QuicklookOlciOpImage(sources, hints, detectors, sza, 
      solar_flux, pc, bands, coefficients, layout);
}
 
Example #17
Source File: QuicklookOlciOpImage.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Constructs a <code>QuicklookOlciOpImage</code>.
 * 
 * <p>
 * The <code>layout</code> parameter may optionally contain the tile grid 
 * layout, sample model, and/or color model. The image dimension is
 * determined by the intersection of the bounding boxes of the source images.
 * 
 * For OLCI dataset, all the sources has the same dimension, and color model.
 * 
 * <p>
 * The image layout of the first source image, <code>source1</code>, is 
 * used as the fallback for the image layout of the destination image. The
 * destination number of bands is the sum of all source image bands.
 * 
 * @param sources <code>List</code> of sources [Red, Green, Blue].
 * @param config Configurable attributes of the image including configuration
 *  variables indexed by <code>RenderingHints.Key</code>s and image 
 *  properties indexed by <code>String</code>s or 
 *  <code>CaselessStringKey</code>s. This is simply forwarded to the 
 *  superclass constructor.
 * @param detectors Array of detectors indexes.
 * @param sza Array of Sun azimuth angle.
 * @param solar_flux solar flux.
 * @param layout The destination image layout.
 */
public QuicklookOlciOpImage(List sources, Map config,
   short[][] detectors, double[][] sza, float[][] solar_flux,
   PixelCorrection[]pixels_correction, int[]bands, int[]bands_coefficients,
   ImageLayout layout)
{
   super(vectorize(sources), layoutHelper(sources, layout, false), config,
         true);
   
   // Set flag to permit in-place operation.
   permitInPlaceOperation();
   
   this.detectors = detectors;
   
   this.sza = sza;
   this.hasSza = sza!=null;
   
   this.solarFlux = solar_flux;
   
   this.bands = bands;
   this.bandsCoefficients = bands_coefficients;
   
   this.pixelsCorrection = pixels_correction;      
   this.hasPixelCorrection = pixels_correction!=null;
   if (this.hasPixelCorrection)
      for (PixelCorrection pc: pixels_correction)
         this.hasPixelCorrection &= pc!=null;
   
   // get ColorModels for IndexColorModel support
   int numSrcs = sources.size();
   colorModels = new ColorModel[numSrcs];
   for (int i = 0; i < numSrcs; i++)
      colorModels[i] = ((RenderedImage) sources.get(i)).getColorModel();
}
 
Example #18
Source File: ImageTiler.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
private PlanarImage makeTiledImage(PlanarImage img, int tileWidth, int tileHeight) {
    ImageLayout tileLayout = new ImageLayout(img);
    tileLayout.setTileWidth(tileWidth);
    tileLayout.setTileHeight(tileHeight);
    tileLayout.setSampleModel(img.getColorModel().createCompatibleSampleModel(tileWidth,tileHeight));
    tileLayout.setColorModel(img.getColorModel());
    RenderingHints tileHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, tileLayout);
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(img);
    PlanarImage pi = JAI.create("format", pb, tileHints);
    pi.getWidth();
    return pi;
}
 
Example #19
Source File: WarpNearestOpImage.java    From geowave with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a WarpNearestOpImage.
 *
 * @param source The source image.
 * @param config RenderingHints used in calculations.
 * @param layout The destination image layout.
 * @param warp An object defining the warp algorithm.
 * @param interp An object describing the interpolation method.
 * @param roi input ROI object used.
 * @param noData NoData Range object used for checking if NoData are present.
 */
public WarpNearestOpImage(
    final RenderedImage source,
    final Map<?, ?> config,
    final ImageLayout layout,
    final Warp warp,
    final Interpolation interp,
    final ROI sourceROI,
    final Range noData,
    final double[] bkg) {
  super(
      source,
      layout,
      config,
      false,
      null, // extender not needed in
      // nearest-neighbor
      // interpolation
      interp,
      warp,
      bkg,
      sourceROI,
      noData);

  /*
   * If the source has IndexColorModel, override the default setting in OpImage. The dest shall
   * have exactly the same SampleModel and ColorModel as the source. Note, in this case, the
   * source should have an integral data type.
   */
  final ColorModel srcColorModel = source.getColorModel();
  if (srcColorModel instanceof IndexColorModel) {
    sampleModel = source.getSampleModel().createCompatibleSampleModel(tileWidth, tileHeight);
    colorModel = srcColorModel;
  }

  /*
   * Selection of a destinationNoData value for each datatype
   */
  final SampleModel sm = source.getSampleModel();
  // Source image data Type
  final int srcDataType = sm.getDataType();

  // Creation of a lookuptable containing the values to use for no data
  if ((srcDataType == DataBuffer.TYPE_BYTE) && hasNoData) {
    final int numBands = getNumBands();
    byteLookupTable = new byte[numBands][256];
    for (int b = 0; b < numBands; b++) {
      for (int i = 0; i < byteLookupTable[0].length; i++) {
        final byte value = (byte) i;
        if (noDataRange.contains(value)) {
          byteLookupTable[b][i] = (byte) backgroundValues[b];
        } else {
          byteLookupTable[b][i] = value;
        }
      }
    }
  }
}
 
Example #20
Source File: GeoWaveRasterReader.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public ImageLayout getImageLayout() throws IOException {
  throw new UnsupportedOperationException(
      "A coverage name must be provided, there is no support for a default coverage");
}
 
Example #21
Source File: Sentinel2Image.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
public static RenderedImage process1BImage (DrbCollectionImage source, 
   int bands, int horizontal_padding, int vertical_padding)
{
   // Prepare output mosaic layout
   ImageLayout layout = new ImageLayout();
   boolean isLayoutTileSet = false;

   // Prepare variables for building output strip mosaic
   int currentWidth = horizontal_padding;
   int currentHeight = vertical_padding;
   
   ParameterBlockJAI mosaicParameters = 
      new ParameterBlockJAI("Mosaic", "rendered");
   
   mosaicParameters.setParameter("mosaicType",
      javax.media.jai.operator.MosaicDescriptor.MOSAIC_TYPE_BLEND);
   
   Collection<DrbImage>images = source.getChildren();
   Iterator<DrbImage> image_it = images.iterator();
   while (image_it.hasNext())
   {
      RenderedImage current_image = null;

      // Select the working bands
      ParameterBlock pb = new ParameterBlock();
      DrbImage fmt = null;
      if (bands>1)
      {
         for (int i=0; i<bands; i++)
         {
            fmt = image_it.next();
            ParameterBlock fmt_pb = new ParameterBlock();
            fmt_pb.addSource(fmt);
            fmt_pb.add(DataBuffer.TYPE_BYTE);
            RenderedOp op = JAI.create("Format", fmt_pb);
         
            pb.addSource(op);
         }
         current_image = JAI.create("bandMerge", pb);
      }
      else
      {
         //Probably PVI image
         current_image = image_it.next();
      }
      
      // Set layout tile size if not already done
      if (!isLayoutTileSet)
      {
         layout.setTileWidth(current_image.getTileWidth());
         layout.setTileHeight(current_image.getTileHeight());
         layout.setColorModel(current_image.getColorModel());
         layout.setSampleModel(current_image.getSampleModel());

         isLayoutTileSet = true;
      }

      // Translate strip to the output coordinate (vertical shift)
      ParameterBlock translateParameters = new ParameterBlock();

      translateParameters.addSource(current_image);
      translateParameters.add((float) currentWidth);
      translateParameters.add((float) currentHeight);
      translateParameters.add(new InterpolationNearest());

      current_image = JAI.create("translate", translateParameters,
         new RenderingHints(JAI.KEY_IMAGE_LAYOUT,layout));

      // TODO: find a way to retrieves the granules position within
      // the mosaic. 
      // Update following strip translation
      /*
      if ((source_index%13)==0)
      {*/
         currentWidth=horizontal_padding;
         currentHeight += current_image.getHeight() + vertical_padding;
         /*
      }
      else
      {
         currentWidth += current_image.getWidth() + horizontal_padding;
      }*/

      // Add current strip to the output mosaic
      mosaicParameters.addSource(current_image);
      // Go to the next image
   }
   double [] backgroundValues = new double [bands];
   for (int j = 0; j < bands; j++) {
       backgroundValues[j] = 0.0D;
   }        
   mosaicParameters.setParameter("backgroundValues", backgroundValues);
   // Create output mosaic
   return JAI.create("mosaic", mosaicParameters,
      new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));
}
 
Example #22
Source File: ManipulationUtils.java    From orbit-image-analysis with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Defines RenderingHints for JAI create operations (otherwise JAI will use defaultTileSize tiling)
 *
 * @param image
 * @return
 */
public static RenderingHints getRenderingHints(PlanarImage image) {
    ImageLayout layout = new ImageLayout(image.getMinX(), image.getMinY(), image.getWidth(), image.getHeight(), image.getTileGridXOffset(), image.getTileGridYOffset(), image.getTileWidth(), image.getTileHeight(), image.getSampleModel(), image.getColorModel());
    RenderingHints renderingHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
    return renderingHints;
}