当前位置: 首页>>代码示例>>Java>>正文


Java ImageLayout.setSampleModel方法代码示例

本文整理汇总了Java中javax.media.jai.ImageLayout.setSampleModel方法的典型用法代码示例。如果您正苦于以下问题:Java ImageLayout.setSampleModel方法的具体用法?Java ImageLayout.setSampleModel怎么用?Java ImageLayout.setSampleModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.media.jai.ImageLayout的用法示例。


在下文中一共展示了ImageLayout.setSampleModel方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import javax.media.jai.ImageLayout; //导入方法依赖的package包/类
/**
 * Wrap the src coverage in the dst layout. <BR>
 * The resulting RenderedImage will contain the data in src, and will be accessible via the grid specs of dst,
 * 
 * @param src the data coverage to be remapped on dst grid
 * @param dst the provider of the final grid
 * @param nodata the nodata value to set for cells not covered by src but included in dst. All bands will share the same nodata value.
 * @return an instance of Coverage2RenderedImageAdapter
 */
public static GridCoverage2DRIA create(final GridCoverage2D src, final GridCoverage2D dst,
        final double nodata) {

    // === Create Layout
    final ImageLayout imageLayout = new ImageLayout(dst.getRenderedImage());

    //
    // SampleModel and ColorModel are related to data itself, so we
    // copy them from the source

    imageLayout.setColorModel(src.getRenderedImage().getColorModel());
    imageLayout.setSampleModel(src.getRenderedImage().getSampleModel());

    // === BorderExtender
    //
    // We have yet to check for it usefulness: it might be more convenient
    // to check for region overlapping and return a nodata value by hand,
    // so to avoid problems with interpolation at source raster borders.
    //
    BorderExtender extender = new BorderExtenderConstant(new double[] { nodata });

    return new GridCoverage2DRIA(src, dst, vectorize(src.getRenderedImage()), imageLayout,
            null, false, extender, Interpolation.getInstance(Interpolation.INTERP_NEAREST),
            new double[] { nodata });
}
 
开发者ID:geosolutions-it,项目名称:soil_sealing,代码行数:35,代码来源:GridCoverage2DRIA.java

示例2: makeTiledImage

import javax.media.jai.ImageLayout; //导入方法依赖的package包/类
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;
}
 
开发者ID:mstritt,项目名称:orbit-image-analysis,代码行数:14,代码来源:ImageTiler.java

示例3: layoutHelper

import javax.media.jai.ImageLayout; //导入方法依赖的package包/类
/**
 * Sets up the image layout information for this Op.
 * The minX, minY, width, and height are calculated based on
 * the source's dimension and padding values. Any of these
 * values specified in the layout parameter is ignored.
 * All other variables are taken from the layout parameter or
 * inherited from the source.
 */
private static ImageLayout layoutHelper(ImageLayout layout,
                                        RenderedImage source,
                                        int leftPad,
                                        int rightPad,
                                        int topPad,
                                        int bottomPad) {
    ImageLayout il = layout == null ?
        new ImageLayout() : (ImageLayout)layout.clone();

    // Set the image bounds according to the padding.
    il.setMinX(source.getMinX() - leftPad);
    il.setMinY(source.getMinY() - topPad);
    il.setWidth(source.getWidth() + leftPad + rightPad);
    il.setHeight(source.getHeight() + topPad + bottomPad);

    // Set tile grid offset to minimize the probability that a
    // tile's bounds does not intersect the source image bounds.
    if(!il.isValid(ImageLayout.TILE_GRID_X_OFFSET_MASK)) {
        il.setTileGridXOffset(il.getMinX(null));
    }

    if (!il.isValid(ImageLayout.TILE_GRID_Y_OFFSET_MASK)) {
        il.setTileGridYOffset(il.getMinY(null));
    }

    // Force inheritance of source image SampleModel and ColorModel.
    il.setSampleModel(source.getSampleModel());
    il.setColorModel(source.getColorModel());

    return il;
}
 
开发者ID:RoProducts,项目名称:rastertheque,代码行数:40,代码来源:BorderOpImage.java

示例4: layoutHelper

import javax.media.jai.ImageLayout; //导入方法依赖的package包/类
/**
    * Force the destination image to be single-banded.
    */
   private static ImageLayout layoutHelper(ImageLayout layout,
                                           RenderedImage source) {
       // Create or clone the layout.
       ImageLayout il = layout == null ?
    new ImageLayout() : (ImageLayout)layout.clone();

       // Force the destination and source origins and dimensions to coincide.
       il.setMinX(source.getMinX());
       il.setMinY(source.getMinY());
       il.setWidth(source.getWidth());
       il.setHeight(source.getHeight());

       // Get the SampleModel.
       SampleModel sm = il.getSampleModel(source);

       // Make sure that this OpImage is single-banded.
       if (sm.getNumBands() != 1) {
           sm =
               RasterFactory.createComponentSampleModel(sm,
                                                        sm.getTransferType(),
                                                        sm.getWidth(),
                                                        sm.getHeight(),
                                                        1);
    il.setSampleModel(sm);
       }

       il.setColorModel(null);

return il;
   }
 
开发者ID:RoProducts,项目名称:rastertheque,代码行数:34,代码来源:ColorQuantizerOpImage.java

示例5: getImageLayout

import javax.media.jai.ImageLayout; //导入方法依赖的package包/类
@Override
public ImageLayout getImageLayout(String name) throws IOException
{
  log.fine("Getting JAI layout for: " + name);

  if (!checkName(name)) {
    throw new IllegalArgumentException("The specified coverage " + name + "is not found");
  }

  // get the pixel size of the base image
  try
  {
    MrsImageDataProvider dp = DataProviderFactory
        .getMrsImageDataProvider(name, DataProviderFactory.AccessMode.READ, providerProperties);
    MrsPyramidMetadata meta = dp.getMetadataReader().read();

    LongRectangle bounds = meta.getPixelBounds(meta.getMaxZoomLevel());

    ImageLayout layout = new ImageLayout();
    layout.setMinX(0);
    layout.setMinY(0);
    layout.setWidth((int)bounds.getWidth());
    layout.setHeight((int)bounds.getHeight());

    // only 1 tile!
    layout.setTileGridXOffset(0);
    layout.setTileGridYOffset(0);

    layout.setTileWidth((int)bounds.getWidth());
    layout.setTileHeight((int)bounds.getHeight());

    MrsImageReader r = dp.getMrsTileReader(meta.getMaxZoomLevel());

    final Iterator<MrGeoRaster> it = r.get();
    try
    {
      Raster raster = it.next().toRaster();

      layout.setColorModel(RasterUtils.createColorModel(raster));
      layout.setSampleModel(raster.getSampleModel());
    }
    finally
    {
      if (!r.canBeCached() && it instanceof Closeable)
      {
        ((Closeable) it).close();
        r.close();
      }
    }

    return layout;
  }
  catch (IOException e)
  {
    e.printStackTrace();
  }

  return null;

}
 
开发者ID:ngageoint,项目名称:mrgeo-geoserver-plugin,代码行数:61,代码来源:MrGeoReader.java

示例6: getScaledImage

import javax.media.jai.ImageLayout; //导入方法依赖的package包/类
private RenderedImage getScaledImage(Band srcBand) throws IOException {
    RenderedImage sourceImage = srcBand.getSourceImage();
    /* This would be more rigorous, but may take a lot of time
    final RenderedOp minMaxOp = ExtremaDescriptor.create(sourceImage, null, 1, 1, false, 1, null);
    double[][] minMax = (double[][]) minMaxOp.getProperty("extrema");
    double min = minMax[0][0];
    double max = minMax[1][0];*/
    final Stx stx = srcBand.getStx();
    final double min = stx.getMinimum();
    final double max = stx.getMaximum();
    final double newMin = min < 0.0 ? Short.MIN_VALUE : 0;
    final double newMax = min < 0.0 ? Short.MAX_VALUE : 65535;
    final double offset = (newMin - min * (newMax - newMin) / (max - min));
    final double scale = (newMax - newMin) / (max - min);
    final int sourceDataType = srcBand.getDataType();
    int targetDataType;
    switch (sourceDataType) {
        case ProductData.TYPE_INT8:
        case ProductData.TYPE_UINT8:
        case ProductData.TYPE_INT16:
        case ProductData.TYPE_UINT16:
            targetDataType = sourceDataType;
            break;
        default:
            targetDataType = min < 0.0 ? ProductData.TYPE_INT16 : ProductData.TYPE_UINT16;
            break;
    }
    if (sourceDataType != targetDataType) {
        ImageLayout imageLayout = new ImageLayout(sourceImage.getMinX(), sourceImage.getMinY(),
                                                  sourceImage.getWidth(), sourceImage.getHeight());
        imageLayout.setSampleModel(
                new SingleBandedSampleModel(ImageManager.getDataBufferType(targetDataType), sourceImage.getWidth(), sourceImage.getHeight()));
        Map<RenderingHints.Key, Object> map = new HashMap<>();
        map.put(JAI.KEY_IMAGE_LAYOUT, imageLayout);
        RenderingHints hints = new RenderingHints(map);
        RenderedOp renderedOp = RescaleDescriptor.create(sourceImage, new double[] { scale }, new double[] { offset }, hints);
        sourceImage = renderedOp.getRendering();
        this.metadata.setBandInfo(getSourceProduct().getBandIndex(srcBand.getName()),
                                  srcBand.getName(),
                                  scale,
                                  offset);
    } else {
        srcBand.readRasterDataFully();
        this.metadata.setBandInfo(getSourceProduct().getBandIndex(srcBand.getName()),
                                  srcBand.getName(), 1, 0);
    }
    return sourceImage;
}
 
开发者ID:senbox-org,项目名称:s2tbx,代码行数:49,代码来源:JP2ProductWriter.java

示例7: layoutHelper

import javax.media.jai.ImageLayout; //导入方法依赖的package包/类
/**
 * Override the dimension specification for the destination such that it
 * has width and height which are equal to non-negative powers of 2.
 */
private static ImageLayout layoutHelper(ImageLayout layout,
                                        RenderedImage source) {
    // Create an ImageLayout or clone the one passed in.
    ImageLayout il = layout == null ?
        new ImageLayout() : (ImageLayout)layout.clone();

    // Force the origin to coincide with that of the source.
    il.setMinX(source.getMinX());
    il.setMinY(source.getMinY());

    // Recalculate the non-unity dimensions to be a positive power of 2.
    // XXX This calculation should not be effected if an implementation
    // of the FCT which supports arbitrary dimensions is used.
    boolean createNewSampleModel = false;
    int w = il.getWidth(source);
    if(w > 1) {
        int newWidth = MathJAI.nextPositivePowerOf2(w);
        if(newWidth != w) {
            il.setWidth(w = newWidth);
            createNewSampleModel = true;
        }
    }
    int h = il.getHeight(source);
    if(h > 1) {
        int newHeight = MathJAI.nextPositivePowerOf2(h);
        if(newHeight != h) {
            il.setHeight(h = newHeight);
            createNewSampleModel = true;
        }
    }

    // Force the image to contain floating point data.
    SampleModel sm = il.getSampleModel(source);
    int dataType = sm.getTransferType();
    if(dataType != DataBuffer.TYPE_FLOAT &&
       dataType != DataBuffer.TYPE_DOUBLE) {
        dataType = DataBuffer.TYPE_FLOAT;
        createNewSampleModel = true;
    }

    // Create a new SampleModel for the destination.
    if(createNewSampleModel) {
        sm = RasterFactory.createComponentSampleModel(sm, dataType, w, h,
                                                      sm.getNumBands());
        il.setSampleModel(sm);

        // Clear the ColorModel mask if needed.
        ColorModel cm = il.getColorModel(null);
        if(cm != null &&
           !JDKWorkarounds.areCompatibleDataModels(sm, cm)) {
            // Clear the mask bit if incompatible.
            il.unsetValid(ImageLayout.COLOR_MODEL_MASK);
        }
    }

    return il;
}
 
开发者ID:RoProducts,项目名称:rastertheque,代码行数:62,代码来源:DCTOpImage.java

示例8: layoutHelper

import javax.media.jai.ImageLayout; //导入方法依赖的package包/类
private static ImageLayout layoutHelper(Vector sources,
                                        ImageLayout il) {

    ImageLayout layout = (il == null) ? new ImageLayout() : (ImageLayout)il.clone();

    int numSources = sources.size();

    // dest data type is the maximum of transfertype of source image
    // utilizing the monotonicity of data types.

    // dest number of bands = sum of source bands
    int destNumBands = totalNumBands(sources);

    int destDataType = DataBuffer.TYPE_BYTE;  // initialize
    RenderedImage srci = (RenderedImage)sources.get(0);
    Rectangle destBounds = new Rectangle(srci.getMinX(),  srci.getMinY(),
                                         srci.getWidth(), srci.getHeight());                                             
    for ( int i = 0; i < numSources; i++ ) {
        srci = (RenderedImage)sources.get(i);
        destBounds = destBounds.intersection(new Rectangle(srci.getMinX(), srci.getMinY(),
                                             srci.getWidth(), srci.getHeight()));

        int typei = srci.getSampleModel().getTransferType();

        // NOTE: this depends on JDK ordering
        destDataType = typei > destDataType ? typei : destDataType;
    }

    SampleModel sm = layout.getSampleModel((RenderedImage)sources.get(0));

    if ( sm.getNumBands() < destNumBands ) {
        int[] destOffsets = new int[destNumBands];

        for(int i=0; i < destNumBands; i++) {
            destOffsets[i] = i;
        }

        // determine the proper width and height to use
        int destTileWidth = sm.getWidth();
        int destTileHeight = sm.getHeight();
        if(layout.isValid(ImageLayout.TILE_WIDTH_MASK))
        {
            destTileWidth =
                layout.getTileWidth((RenderedImage)sources.get(0));
        }
        if(layout.isValid(ImageLayout.TILE_HEIGHT_MASK))
        {
            destTileHeight =
                layout.getTileHeight((RenderedImage)sources.get(0));
        }
        
        sm = RasterFactory.createComponentSampleModel(sm,
                                                      destDataType,
                                                      destTileWidth,
                                                      destTileHeight,
                                                      destNumBands);


        layout.setSampleModel(sm);
    }

    ColorModel cm = layout.getColorModel(null);

    if ( cm != null &&
         !JDKWorkarounds.areCompatibleDataModels(sm, cm)) {
        // Clear the mask bit if incompatible.
        layout.unsetValid(ImageLayout.COLOR_MODEL_MASK);
    }

    return layout;
}
 
开发者ID:RoProducts,项目名称:rastertheque,代码行数:72,代码来源:BandMergeOpImage.java

示例9: layoutHelper

import javax.media.jai.ImageLayout; //导入方法依赖的package包/类
/**
 * Force the destination image to have a signed data type.
 */
private static ImageLayout layoutHelper(ImageLayout layout,
                                        RenderedImage source) {
    // Create or clone the layout.
    ImageLayout il = layout == null ?
        new ImageLayout() : (ImageLayout)layout.clone();

    // Get the reference SampleModel.
    SampleModel sm = il.getSampleModel(source);

    // Get the data type.
    int dataType = sm.getTransferType();

    // Determine whether the destination requires a different data type
    // and set it if so.
    boolean createNewSampleModel = false;
    if(dataType == DataBuffer.TYPE_BYTE) {
        dataType = DataBuffer.TYPE_SHORT;
        createNewSampleModel = true;
    } else if(dataType == DataBuffer.TYPE_USHORT) {
        dataType = DataBuffer.TYPE_INT;
        createNewSampleModel = true;
    }

    // Create a new SampleModel for the destination if necessary.
    if(createNewSampleModel) {
        sm = RasterFactory.createComponentSampleModel(sm, dataType,
                                                      sm.getWidth(),
                                                      sm.getHeight(),
                                                      sm.getNumBands());

        il.setSampleModel(sm);

        // Check ColorModel.
        ColorModel cm = il.getColorModel(null);
        if(cm != null &&
           !JDKWorkarounds.areCompatibleDataModels(sm, cm)) {
            // Clear the mask bit if incompatible.
            il.unsetValid(ImageLayout.COLOR_MODEL_MASK);
        }
    }

    return il;
}
 
开发者ID:RoProducts,项目名称:rastertheque,代码行数:47,代码来源:ConjugateOpImage.java


注:本文中的javax.media.jai.ImageLayout.setSampleModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。