本文整理汇总了Java中javax.media.jai.RasterFactory类的典型用法代码示例。如果您正苦于以下问题:Java RasterFactory类的具体用法?Java RasterFactory怎么用?Java RasterFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RasterFactory类属于javax.media.jai包,在下文中一共展示了RasterFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BandCombineOpImage
import javax.media.jai.RasterFactory; //导入依赖的package包/类
/**
* Constructor.
*
* @param source The source image.
* @param layout The destination image layout.
* @param matrix The matrix of values used to perform the
* linear combination.
*/
public BandCombineOpImage(RenderedImage source,
Map config,
ImageLayout layout,
double[][] matrix) {
super(source, layout, config, true);
this.matrix = matrix;
int numBands = matrix.length; // matrix height is dst numBands
if (getSampleModel().getNumBands() != numBands) {
sampleModel = RasterFactory.createComponentSampleModel(sampleModel,
sampleModel.getDataType(),
tileWidth, tileHeight, numBands);
if(colorModel != null &&
!JDKWorkarounds.areCompatibleDataModels(sampleModel,
colorModel)) {
colorModel = ImageUtil.getCompatibleColorModel(sampleModel,
config);
}
}
}
示例2: sampleModelHelper
import javax.media.jai.RasterFactory; //导入依赖的package包/类
private static SampleModel sampleModelHelper(int numBands,
ImageLayout layout) {
SampleModel sampleModel;
if (layout!= null && layout.isValid(ImageLayout.SAMPLE_MODEL_MASK)) {
sampleModel = layout.getSampleModel(null);
if (sampleModel.getNumBands() != numBands) {
throw new RuntimeException(JaiI18N.getString("ImageFunctionRIF0"));
}
} else { // Create a SampleModel.
// Use a dummy width and height, OpImage will fix them
sampleModel = RasterFactory.createBandedSampleModel(
DataBuffer.TYPE_FLOAT,
1, 1,
numBands);
}
return sampleModel;
}
示例3: jiffleProcessExecution
import javax.media.jai.RasterFactory; //导入依赖的package包/类
/**
* Private method used for executing the script operation on an input image with the selected GridGeometry2D.
*
* @param input RenderedImage to process
* @param jb jiffleBuilder object with the script to execute
* @param destGridGeometry GridGeometry object associated to the output image
* @return img output image generated from the script
* @throws JiffleException
*/
private RenderedImage jiffleProcessExecution(RenderedImage input, JiffleBuilder jb,
GridGeometry2D destGridGeometry) throws JiffleException {
// Setting of the source
jb.source("image", input, null, false);
// Now we specify the tile dimensions of the final image
int tileWidth = input.getTileWidth();
int tileHeight = input.getTileHeight();
// Creation of a SampleModel associated with the final image
SampleModel sm = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_DOUBLE,
tileWidth, tileHeight, 1);
// Selection of the GridEnvelope associated to the input coverage
final GridEnvelope2D gr2d = destGridGeometry.getGridRange2D();
// Final image creation
final WritableRenderedImage img = new TiledImage(gr2d.x, gr2d.y, gr2d.width, gr2d.height,
0, 0, sm, PlanarImage.createColorModel(sm));
// Setting of the final image
jb.dest("dest", img);
// Finally we run the script and retrieve the resulting image.
jb.run();
return img;
}
示例4: createEdgesRaster
import javax.media.jai.RasterFactory; //导入依赖的package包/类
private WritableRaster createEdgesRaster( int width, int height, int[] pixels ) {
int dataType = DataBuffer.TYPE_DOUBLE;
ComponentSampleModel sampleModel = new ComponentSampleModel(dataType, width, height, 1,
width, new int[]{0});
WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, null);
int index = 0;
for( int y = 0; y < height; y++ ) {
for( int x = 0; x < width; x++ ) {
double value = (double) pixels[index];
if (value != -1) {
value = HMConstants.doubleNovalue;
} else {
value = 1.0;
}
raster.setSample(x, y, 0, value);
index++;
}
}
return raster;
}
示例5: createRasterTypeDouble
import javax.media.jai.RasterFactory; //导入依赖的package包/类
public static WritableRaster createRasterTypeDouble(
final int numBands,
final int tileSize ) {
final WritableRaster raster = RasterFactory.createBandedRaster(
DataBuffer.TYPE_DOUBLE,
tileSize,
tileSize,
numBands,
null);
final double[] defaultValues = new double[tileSize * tileSize * numBands];
Arrays.fill(
defaultValues,
Double.NaN);
raster.setDataElements(
0,
0,
tileSize,
tileSize,
defaultValues);
return raster;
}
示例6: computeRect
import javax.media.jai.RasterFactory; //导入依赖的package包/类
@Override
protected void computeRect(PlanarImage[] sourceImages, WritableRaster tile, Rectangle destRect) {
final BufferedImage image = new BufferedImage(colorModel,
RasterFactory.createWritableRaster(tile.getSampleModel(),
tile.getDataBuffer(),
new Point(0, 0)), false, null);
final Graphics2D graphics2D = image.createGraphics();
graphics2D.translate(-(tile.getMinX() + 0.5), -(tile.getMinY() + 0.5));
graphics2D.setColor(Color.WHITE);
FeatureIterator<SimpleFeature> featureIterator = featureCollection.features();
try {
AffineTransform transform = AffineTransform.getScaleInstance(1.0 / getScale(), 1.0 / getScale());
// transform.concatenate(m2iTransform);
AffineTransform2D transform2D = new AffineTransform2D(transform);
while (featureIterator.hasNext()) {
SimpleFeature feature = featureIterator.next();
Object value = feature.getDefaultGeometry();
if (value instanceof Geometry) {
try {
renderGeometry((Geometry) value, graphics2D, transform2D);
} catch (Exception ignored) {
// ignore
}
}
}
} finally {
featureIterator.close();
}
graphics2D.dispose();
final byte[] data = ((DataBufferByte) tile.getDataBuffer()).getData();
for (int i = 0; i < data.length; i++) {
data[i] = (data[i] != 0) ? TRUE : FALSE;
}
}
示例7: makeSampleModel
import javax.media.jai.RasterFactory; //导入依赖的package包/类
private static SampleModel makeSampleModel(int width, int height,
Number[] bandValues) {
int numBands = bandValues.length;
int dataType;
if (bandValues instanceof Byte[]) {
dataType = DataBuffer.TYPE_BYTE;
} else if (bandValues instanceof Short[]) {
/* If all band values are positive, use UShort, else use Short. */
dataType = DataBuffer.TYPE_USHORT;
Short[] shortValues = (Short[])bandValues;
for (int i = 0; i < numBands; i++) {
if (shortValues[i].shortValue() < 0) {
dataType = DataBuffer.TYPE_SHORT;
break;
}
}
} else if (bandValues instanceof Integer[]) {
dataType = DataBuffer.TYPE_INT;
} else if (bandValues instanceof Float[]) {
dataType = DataBuffer.TYPE_FLOAT;
} else if (bandValues instanceof Double[]) {
dataType = DataBuffer.TYPE_DOUBLE;
} else {
dataType = DataBuffer.TYPE_UNDEFINED;
}
return RasterFactory.createPixelInterleavedSampleModel(
dataType, width, height, numBands);
}
示例8: layoutHelper
import javax.media.jai.RasterFactory; //导入依赖的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;
}
示例9: createDoubleWritableRaster
import javax.media.jai.RasterFactory; //导入依赖的package包/类
private WritableRaster createDoubleWritableRaster( int width, int height, int[] pixels ) {
int dataType = DataBuffer.TYPE_DOUBLE;
ComponentSampleModel sampleModel = new ComponentSampleModel(dataType, width, height, 1,
width, new int[]{0});
WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, null);
int index = 0;
for( int y = 0; y < height; y++ ) {
for( int x = 0; x < width; x++ ) {
raster.setSample(x, y, 0, (double) pixels[index]);
index++;
}
}
return raster;
}
示例10: createCoverageFromTemplate
import javax.media.jai.RasterFactory; //导入依赖的package包/类
/**
* Creates a new {@link GridCoverage2D} using an existing as template.
*
* @param template the template to use.
* @param value the value to set the new raster to, if not <code>null</code>.
* @param writableRasterHolder an array of length 1 to place the writable raster in, that
* was can be used to populate the coverage. If <code>null</code>, it is ignored.
* @return the new coverage.
*/
public static GridCoverage2D createCoverageFromTemplate( GridCoverage2D template, Double value,
WritableRaster[] writableRasterHolder ) {
RegionMap regionMap = getRegionParamsFromGridCoverage(template);
double west = regionMap.getWest();
double south = regionMap.getSouth();
double east = regionMap.getEast();
double north = regionMap.getNorth();
int cols = regionMap.getCols();
int rows = regionMap.getRows();
ComponentSampleModel sampleModel = new ComponentSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, 1, cols, new int[]{0});
WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, null);
if (value != null) {
// autobox only once
double v = value;
for( int y = 0; y < rows; y++ ) {
for( int x = 0; x < cols; x++ ) {
raster.setSample(x, y, 0, v);
}
}
}
if (writableRasterHolder != null) {
writableRasterHolder[0] = raster;
}
Envelope2D writeEnvelope = new Envelope2D(template.getCoordinateReferenceSystem(), west, south, east - west,
north - south);
GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null);
GridCoverage2D coverage2D = factory.create("newraster", raster, writeEnvelope);
return coverage2D;
}
示例11: createSubCoverageFromTemplate
import javax.media.jai.RasterFactory; //导入依赖的package包/类
/**
* Create a subcoverage given a template coverage and an envelope.
*
* @param template the template coverage used for the resolution.
* @param subregion the envelope to extract to the new coverage. This should
* be snapped on the resolution of the coverage, in order to avoid
* shifts.
* @param value the value to set the new raster to, if not <code>null</code>.
* @param writableRasterHolder an array of length 1 to place the writable raster in, that
* was can be used to populate the coverage. If <code>null</code>, it is ignored.
* @return the new coverage.
*/
public static GridCoverage2D createSubCoverageFromTemplate( GridCoverage2D template, Envelope2D subregion, Double value,
WritableRaster[] writableRasterHolder ) {
RegionMap regionMap = getRegionParamsFromGridCoverage(template);
double xRes = regionMap.getXres();
double yRes = regionMap.getYres();
double west = subregion.getMinX();
double south = subregion.getMinY();
double east = subregion.getMaxX();
double north = subregion.getMaxY();
int cols = (int) ((east - west) / xRes);
int rows = (int) ((north - south) / yRes);
ComponentSampleModel sampleModel = new ComponentSampleModel(DataBuffer.TYPE_DOUBLE, cols, rows, 1, cols, new int[]{0});
WritableRaster writableRaster = RasterFactory.createWritableRaster(sampleModel, null);
if (value != null) {
// autobox only once
double v = value;
for( int y = 0; y < rows; y++ ) {
for( int x = 0; x < cols; x++ ) {
writableRaster.setSample(x, y, 0, v);
}
}
}
if (writableRasterHolder != null)
writableRasterHolder[0] = writableRaster;
Envelope2D writeEnvelope = new Envelope2D(template.getCoordinateReferenceSystem(), west, south, east - west,
north - south);
GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null);
GridCoverage2D coverage2D = factory.create("newraster", writableRaster, writeEnvelope);
return coverage2D;
}
示例12: normalVector
import javax.media.jai.RasterFactory; //导入依赖的package包/类
protected WritableRaster normalVector( WritableRaster pitWR, double res ) {
int minX = pitWR.getMinX();
int minY = pitWR.getMinY();
int rows = pitWR.getHeight();
int cols = pitWR.getWidth();
RandomIter pitIter = RandomIterFactory.create(pitWR, null);
/*
* Initialize the Image of the normal vector in the central point of the
* cells, which have 3 components so the Image have 3 bands..
*/
SampleModel sm = RasterFactory.createBandedSampleModel(5, cols, rows, 3);
WritableRaster tmpNormalVectorWR = CoverageUtilities.createWritableRaster(cols, rows, null, sm, 0.0);
WritableRandomIter tmpNormaIter = RandomIterFactory.createWritable(tmpNormalVectorWR, null);
/*
* apply the corripio's formula (is the formula (3) in the article)
*/
for( int j = minY; j < minX + rows - 1; j++ ) {
for( int i = minX; i < minX + cols - 1; i++ ) {
double zij = pitIter.getSampleDouble(i, j, 0);
double zidxj = pitIter.getSampleDouble(i + 1, j, 0);
double zijdy = pitIter.getSampleDouble(i, j + 1, 0);
double zidxjdy = pitIter.getSampleDouble(i + 1, j + 1, 0);
double firstComponent = 0.5 * res * (zij - zidxj + zijdy - zidxjdy);
double secondComponent = 0.5 * res * (zij + zidxj - zijdy - zidxjdy);
double thirthComponent = (res * res);
double den = Math.sqrt(firstComponent * firstComponent + secondComponent * secondComponent + thirthComponent
* thirthComponent);
tmpNormaIter.setPixel(i, j, new double[]{firstComponent / den, secondComponent / den, thirthComponent / den});
}
}
pitIter.done();
return tmpNormalVectorWR;
}
示例13: normalVector
import javax.media.jai.RasterFactory; //导入依赖的package包/类
protected WritableRaster normalVector( WritableRaster pitWR, double res ) {
int minX = pitWR.getMinX();
int minY = pitWR.getMinY();
int rows = pitWR.getHeight();
int cols = pitWR.getWidth();
RandomIter pitIter = RandomIterFactory.create(pitWR, null);
/*
* Initializa the Image of the normal vector in the central point of the
* cells, which have 3 components so the Image have 3 bands..
*/
SampleModel sm = RasterFactory.createBandedSampleModel(5, cols, rows, 3);
WritableRaster tmpNormalVectorWR = CoverageUtilities.createWritableRaster(cols, rows, null, sm, 0.0);
WritableRandomIter tmpNormalIter = RandomIterFactory.createWritable(tmpNormalVectorWR, null);
/*
* apply the corripio's formula (is the formula (3) in the article)
*/
for( int j = minY; j < minX + rows - 1; j++ ) {
for( int i = minX; i < minX + cols - 1; i++ ) {
double zij = pitIter.getSampleDouble(i, j, 0);
double zidxj = pitIter.getSampleDouble(i + 1, j, 0);
double zijdy = pitIter.getSampleDouble(i, j + 1, 0);
double zidxjdy = pitIter.getSampleDouble(i + 1, j + 1, 0);
double firstComponent = res * (zij - zidxj + zijdy - zidxjdy);
double secondComponent = res * (zij + zidxj - zijdy - zidxjdy);
double thirthComponent = 2 * (res * res);
double den = Math.sqrt(firstComponent * firstComponent + secondComponent * secondComponent + thirthComponent
* thirthComponent);
tmpNormalIter.setPixel(i, j, new double[]{firstComponent / den, secondComponent / den, thirthComponent / den});
}
}
pitIter.done();
return tmpNormalVectorWR;
}
示例14: PolarToComplexOpImage
import javax.media.jai.RasterFactory; //导入依赖的package包/类
/**
* Constructs a <code>PolarToComplexOpImage</code> object.
*
* <p>The tile grid layout, SampleModel, and ColorModel may optionally
* be specified by an ImageLayout object.
*
* @param magnitude A RenderedImage representing magnitude.
* @param phase A RenderedImage representing phase.
* @param layout An ImageLayout optionally containing the tile grid layout,
* SampleModel, and ColorModel, or null.
*/
public PolarToComplexOpImage(RenderedImage magnitude,
RenderedImage phase,
Map config,
ImageLayout layout) {
super(magnitude, phase, layout, config, true);
// Force the number of bands to be twice the minimum source band count.
int numBands =
2*Math.min(magnitude.getSampleModel().getNumBands(),
phase.getSampleModel().getNumBands());
if(sampleModel.getNumBands() != numBands) {
// Create a new SampleModel for the destination.
sampleModel =
RasterFactory.createComponentSampleModel(sampleModel,
sampleModel.getTransferType(),
sampleModel.getWidth(),
sampleModel.getHeight(),
numBands);
if(colorModel != null &&
!JDKWorkarounds.areCompatibleDataModels(sampleModel,
colorModel)) {
colorModel = ImageUtil.getCompatibleColorModel(sampleModel,
config);
}
}
// Set phase gain and bias as a function of the phase image data type.
switch(phase.getSampleModel().getTransferType()) {
case DataBuffer.TYPE_BYTE:
phaseGain = (2.0*Math.PI)/255.0;
phaseBias = -Math.PI;
break;
case DataBuffer.TYPE_SHORT:
phaseGain = (2.0*Math.PI)/Short.MAX_VALUE;
phaseBias = -Math.PI;
break;
case DataBuffer.TYPE_USHORT:
phaseGain = (2.0*Math.PI)/(Short.MAX_VALUE - Short.MIN_VALUE);
phaseBias = -Math.PI;
break;
case DataBuffer.TYPE_INT:
phaseGain = (2.0*Math.PI)/Integer.MAX_VALUE;
phaseBias = -Math.PI;
break;
default:
// A floating point type: do nothing - use class defaults.
}
// TODO: Set "complex" property.
}
示例15: makePattern
import javax.media.jai.RasterFactory; //导入依赖的package包/类
/** Creates a Raster defining tile (0, 0) of the master pattern. */
private static Raster makePattern(SampleModel sampleModel,
Number[] bandValues) {
WritableRaster pattern = RasterFactory.createWritableRaster(
sampleModel, new Point(0, 0));
int width = sampleModel.getWidth();
int height = sampleModel.getHeight();
int dataType = sampleModel.getTransferType();
int numBands = sampleModel.getNumBands();
switch (dataType) {
case DataBuffer.TYPE_BYTE:
int[] bvalues = new int[numBands];
for (int i = 0; i < numBands; i++) {
bvalues[i] = bandValues[i].intValue() & ImageUtil.BYTE_MASK;
}
/* Put the first scanline in with setPixels. */
for (int x = 0; x < width; x++) {
pattern.setPixel(x, 0, bvalues);
}
break;
case DataBuffer.TYPE_USHORT: // USHORT is less than 127
case DataBuffer.TYPE_SHORT:
case DataBuffer.TYPE_INT:
int[] ivalues = new int[numBands];
for (int i = 0; i < numBands; i++) {
ivalues[i] = bandValues[i].intValue();
}
/* Put the first scanline in with setPixels. */
for (int x = 0; x < width; x++) {
pattern.setPixel(x, 0, ivalues);
}
break;
case DataBuffer.TYPE_FLOAT:
float[] fvalues = new float[numBands];
for (int i = 0; i < numBands; i++) {
fvalues[i] = bandValues[i].floatValue();
}
/* Put the first scanline in with setPixels. */
for (int x = 0; x < width; x++) {
pattern.setPixel(x, 0, fvalues);
}
break;
case DataBuffer.TYPE_DOUBLE:
double[] dvalues = new double[numBands];
for (int i = 0; i < numBands; i++) {
dvalues[i] = bandValues[i].doubleValue();
}
/* Put the first scanline in with setPixels. */
for (int x = 0; x < width; x++) {
pattern.setPixel(x, 0, dvalues);
}
break;
}
/* Copy the first line out. */
Object odata = pattern.getDataElements(0, 0, width, 1, null);
/* Use the first line to copy other rows. */
for (int y = 1; y < height; y++) {
pattern.setDataElements(0, y, width, 1, odata);
}
return pattern;
}