List of usage examples for java.awt.image RenderedImage getSampleModel
SampleModel getSampleModel();
From source file:org.geoserver.wms.animate.FrameCatalogVisitor.java
private long getImageSizeInBytes(RenderedImage image) { int tileWidth = image.getTileWidth(); int tileLength = image.getNumXTiles(); int numBands = image.getSampleModel().getNumBands(); int[] sampleSize = image.getSampleModel().getSampleSize(); return (long) Math.ceil(2 * tileWidth * tileLength * numBands * (sampleSize[0] / 8.0)); }
From source file:org.geoserver.wps.gs.raster.algebra.JiffleScriptProcessTest.java
@Test public void testSimpleScript() throws Exception { if (testCoverage1 != null) { // Script selection String script = FileUtils.readFileToString(new File(JIFFLE_SCRIPT_PATH)); // Process calculation GridCoverage2D finalCoverage = process.execute(testCoverage1, script, null, null); // Check the result assertNotNull(finalCoverage);//from ww w .j a va 2s. co m RenderedImage finalImage = finalCoverage.getRenderedImage(); assertEquals(finalImage.getSampleModel().getNumBands(), FINAL_NUM_BANDS); PlanarImage.wrapRenderedImage(finalImage).getTiles(); checkExecution(finalImage, FINAL_VALUES, testCoverage1); finalCoverage.dispose(true); if (finalImage instanceof RenderedOp) { ((RenderedOp) finalImage).dispose(); } } else { LOGGER.log(Level.WARNING, "\nTest1: file " + IMAGE_NAME_1 + " not found in geoserver-enterprise/src/extension/wps/wps-core/src/test/java/org/geoserver/wps/raster/algebra"); } }
From source file:org.geoserver.wps.gs.raster.algebra.JiffleScriptProcessTest.java
@Test public void testSimpleScript2ImagesCombined() throws Exception { if (testCoverage1 != null && testCoverage2 != null) { // Script selection String script = FileUtils.readFileToString(new File(JIFFLE_SCRIPT_PATH)); // Combination of the bands of the 2 images RenderedImage img1 = testCoverage1.getRenderedImage(); RenderedImage img2 = testCoverage2.getRenderedImage(); RenderedImage imgComposed = BandMergeDescriptor.create(img1, img2, hints); GridCoverage2D composedCoverage = new GridCoverageFactory(null).create("New_cov", imgComposed, testCoverage1.getGridGeometry().getEnvelope()); // Process calculation GridCoverage2D finalCoverage = process.execute(composedCoverage, script, null, 0); // Check the result assertNotNull(finalCoverage);//from w w w . j ava 2 s .c om RenderedImage finalImage = finalCoverage.getRenderedImage(); assertEquals(finalImage.getSampleModel().getNumBands(), FINAL_NUM_BANDS); PlanarImage.wrapRenderedImage(finalImage).getTiles(); checkExecution(finalImage, FINAL_VALUES, testCoverage1, testCoverage2); finalCoverage.dispose(true); if (finalImage instanceof RenderedOp) { ((RenderedOp) finalImage).dispose(); } } else { LOGGER.log(Level.WARNING, "\nTest2: files not found in geoserver-enterprise/src/extension/wps/wps-core/src/test/java/org/geoserver/wps/raster/algebra"); } }
From source file:org.geoserver.wps.gs.raster.algebra.JiffleScriptProcessTest.java
@Test public void testSimpleScriptMultiBandedImage() throws Exception { if (testCoverage3 != null) { // Script selection String script = FileUtils.readFileToString(new File(JIFFLE_SCRIPT_PATH)); // Process calculation GridCoverage2D finalCoverage = process.execute(testCoverage3, script, null, 0); // Check the result assertNotNull(finalCoverage);// w ww .jav a2 s.co m RenderedImage finalImage = finalCoverage.getRenderedImage(); assertEquals(finalImage.getSampleModel().getNumBands(), FINAL_NUM_BANDS); PlanarImage.wrapRenderedImage(finalImage).getTiles(); checkExecution(finalImage, FINAL_VALUES, testCoverage3); finalCoverage.dispose(true); if (finalImage instanceof RenderedOp) { ((RenderedOp) finalImage).dispose(); } } else { LOGGER.log(Level.WARNING, "\nTest3: file " + IMAGE_NAME_3 + " not found in geoserver-enterprise/src/extension/wps/wps-core/src/test/java/org/geoserver/wps/raster/algebra"); } }
From source file:org.geoserver.wps.gs.raster.algebra.JiffleScriptProcessTest.java
@Test public void testOnAllBands() throws Exception { if (testCoverage3 != null) { // Script selection String script = FileUtils.readFileToString(new File(JIFFLE_SCRIPT_PATH)); // Process calculation List<String> scripts = new ArrayList<String>(1); scripts.add(script);/*from w w w . j av a 2 s .co m*/ GridCoverage2D finalCoverage = process2.execute(testCoverage3, scripts); // Check the result assertNotNull(finalCoverage); RenderedImage finalImage = finalCoverage.getRenderedImage(); // Check on the number of bands int numBandsOut = finalImage.getSampleModel().getNumBands(); int numBandsIn = testCoverage3.getRenderedImage().getSampleModel().getNumBands(); ColorModel cm = testCoverage3.getRenderedImage().getColorModel(); if (cm.hasAlpha() && !cm.isAlphaPremultiplied()) { numBandsIn--; } assertEquals(numBandsIn, numBandsOut); PlanarImage.wrapRenderedImage(finalImage).getTiles(); int[] values = new int[] { MORE_THAN_ZERO_BAND_0, MORE_THAN_ZERO_BAND_0, MORE_THAN_ZERO_BAND_0 }; checkExecution(finalImage, values, testCoverage3); finalCoverage.dispose(true); if (finalImage instanceof RenderedOp) { ((RenderedOp) finalImage).dispose(); } } else { LOGGER.log(Level.WARNING, "\nTest5: file " + IMAGE_NAME_3 + " not found in geoserver-enterprise/src/extension/wps/wps-core/src/test/java/org/geoserver/wps/raster/algebra"); } }
From source file:org.geoserver.wps.gs.raster.algebra.JiffleScriptProcessTest.java
@Test public void testOnAllBandsMultiScripts() throws Exception { if (testCoverage3 != null) { // Script1 selection String script = FileUtils.readFileToString(new File(JIFFLE_SCRIPT_PATH)); // Script2 selection String script2 = FileUtils.readFileToString(new File(JIFFLE_SCRIPT_2_PATH)); // Process calculation List<String> scripts = new ArrayList<String>(1); scripts.add(script);//from www . j a va 2 s . c o m scripts.add(script2); scripts.add(script2); GridCoverage2D finalCoverage = process2.execute(testCoverage3, scripts); // Check the result assertNotNull(finalCoverage); RenderedImage finalImage = finalCoverage.getRenderedImage(); // Check on the number of bands int numBandsOut = finalImage.getSampleModel().getNumBands(); int numBandsIn = testCoverage3.getRenderedImage().getSampleModel().getNumBands(); ColorModel cm = testCoverage3.getRenderedImage().getColorModel(); if (cm != null && cm instanceof ComponentColorModel && cm.hasAlpha() && !cm.isAlphaPremultiplied()) { numBandsIn--; } assertEquals(numBandsIn, numBandsOut); PlanarImage.wrapRenderedImage(finalImage).getTiles(); int[] values = new int[] { MORE_THAN_ZERO_BAND_0, MORE_THAN_ZERO_BAND_1, MORE_THAN_ZERO_BAND_1 }; checkExecution(finalImage, values, testCoverage3); finalCoverage.dispose(true); if (finalImage instanceof RenderedOp) { ((RenderedOp) finalImage).dispose(); } } else { LOGGER.log(Level.WARNING, "\nTest6: file " + IMAGE_NAME_3 + " not found in geoserver-enterprise/src/extension/wps/wps-core/src/test/java/org/geoserver/wps/raster/algebra"); } }
From source file:org.geoserver.wps.gs.raster.algebra.JiffleScriptProcessTest.java
/** * Private method for ensuring the validity of the output image. * /*from w ww. j a v a 2 s. c o m*/ * @param outputImage RenderedImage extracted from the output coverage * @param inputCoverages Input Coverages used. * @param values */ private void checkExecution(RenderedImage outputImage, int[] values, GridCoverage2D... inputCoverages) { RenderedImage inputImage = inputCoverages[0].getRenderedImage(); int numBands = outputImage.getSampleModel().getNumBands(); int minTileX = outputImage.getMinTileX(); int minTileY = outputImage.getMinTileY(); int maxTileX = outputImage.getNumXTiles() + minTileX; int maxTileY = outputImage.getNumYTiles() + minTileY; int minX; int minY; int maxX; int maxY; Raster inputTile; Raster outputTile; int inputValue; int outputValue; // Cycle on each tile int valueOver0; for (int b = 0; b < numBands; b++) { valueOver0 = values[b]; for (int xTile = minTileX; xTile < maxTileX; xTile++) { for (int yTile = minTileY; yTile < maxTileY; yTile++) { inputTile = inputImage.getTile(xTile, yTile); outputTile = outputImage.getTile(xTile, yTile); minX = inputTile.getMinX(); minY = inputTile.getMinY(); maxX = inputTile.getWidth() + minX; maxY = inputTile.getHeight() + minY; // Cycle on the x axis for (int x = minX; x < maxX; x++) { // Cycle on the y axis for (int y = minY; y < maxY; y++) { inputValue = inputTile.getSample(x, y, b); outputValue = outputTile.getSample(x, y, b); // Check if the script operation is performed correctly if (inputValue > 0) { assertEquals(outputValue, valueOver0); } else { assertEquals(outputValue, LESS_THAN_ZERO_BAND_0); } } } } } } }
From source file:org.geotools.gce.imagemosaic.ImageMosaicReaderTest.java
/** * Simple test method accessing time and 2 custom dimensions for the sample * dataset//from www . j a v a 2 s .co m * @throws IOException * @throws FactoryException * @throws NoSuchAuthorityCodeException * @throws ParseException + */ @Test @SuppressWarnings("rawtypes") public void multipleDimensionsStacked() throws Exception { final AbstractGridFormat format = TestUtils.getFormat(timeAdditionalDomainsURL); ImageMosaicReader reader = TestUtils.getReader(timeAdditionalDomainsURL, format); final String[] metadataNames = reader.getMetadataNames(); assertNotNull(metadataNames); assertEquals(metadataNames.length, 14); assertEquals("true", reader.getMetadataValue("HAS_DATE_DOMAIN")); assertEquals("20081031T0000000,20081101T0000000", reader.getMetadataValue("DATE_DOMAIN")); assertEquals("true", reader.getMetadataValue("HAS_DEPTH_DOMAIN")); assertEquals("false", reader.getMetadataValue("HAS_ELEVATION_DOMAIN")); assertEquals("20,100", reader.getMetadataValue("DEPTH_DOMAIN")); // use imageio with defined tiles final ParameterValue<Boolean> useJai = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue(); useJai.setValue(false); final ParameterValue<String> tileSize = AbstractGridFormat.SUGGESTED_TILE_SIZE.createValue(); tileSize.setValue("128,128"); // specify time final ParameterValue<List> time = ImageMosaicFormat.TIME.createValue(); final SimpleDateFormat formatD = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); formatD.setTimeZone(TimeZone.getTimeZone("GMT")); final Date timeD = formatD.parse("2008-10-31T00:00:00.000Z"); time.setValue(new ArrayList() { { add(timeD); } }); // specify additional Dimensions Set<ParameterDescriptor<List>> params = reader.getDynamicParameters(); ParameterValue<List<String>> dateValue = null; final String selectedDate = "20081031T0000000"; for (ParameterDescriptor param : params) { if (param.getName().getCode().equalsIgnoreCase("DATE")) { dateValue = param.createValue(); dateValue.setValue(new ArrayList<String>() { { add(selectedDate); } }); } } // Stacked bands final ParameterValue<String> paramStacked = ImageMosaicFormat.MERGE_BEHAVIOR.createValue(); paramStacked.setValue(MergeBehavior.STACK.toString()); // Test the output coverage GeneralParameterValue[] values = new GeneralParameterValue[] { useJai, tileSize, time, dateValue, paramStacked }; final GridCoverage2D coverage = TestUtils.getCoverage(reader, values, false); assertNotNull(coverage); // inspect reanderedImage final RenderedImage image = coverage.getRenderedImage(); assertEquals("wrong number of bands detected", 2, image.getSampleModel().getNumBands()); }
From source file:org.geotools.gce.imagemosaic.ImageMosaicReaderTest.java
/** * Simple test method accessing time and 2 custom dimensions for the sample * dataset// w w w. j av a 2 s .c o m * @throws IOException * @throws FactoryException * @throws NoSuchAuthorityCodeException * @throws ParseException + */ @Test @SuppressWarnings("rawtypes") public void multipleDimensionsStackedSar() throws Exception { final URL sourceURL = TestData.file(this, "merge").toURI().toURL(); final AbstractGridFormat format = TestUtils.getFormat(sourceURL); ImageMosaicReader reader = TestUtils.getReader(sourceURL, format); final String[] metadataNames = reader.getMetadataNames(); assertNotNull(metadataNames); assertEquals(12, metadataNames.length); assertEquals("false", reader.getMetadataValue("HAS_POLARIZ_DOMAIN")); assertEquals("true", reader.getMetadataValue("HAS_POLARIZATION_DOMAIN")); assertEquals("POLARIZATION", reader.getDynamicParameters().iterator().next().getName().getCode()); assertEquals("HH,HV,VH,VV", reader.getMetadataValue("POLARIZATION_DOMAIN"));// ten characters limitation overcome! assertEquals("true", reader.getMetadataValue("HAS_TIME_DOMAIN")); assertEquals("false", reader.getMetadataValue("HAS_ELEVATION_DOMAIN")); assertEquals("2012-01-01T00:00:00.000Z", reader.getMetadataValue("TIME_DOMAIN")); assertEquals("2012-01-01T00:00:00.000Z", reader.getMetadataValue("TIME_DOMAIN_MINIMUM")); assertEquals("2012-01-01T00:00:00.000Z", reader.getMetadataValue("TIME_DOMAIN_MAXIMUM")); // use imageio with defined tiles final ParameterValue<Boolean> useJai = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue(); useJai.setValue(false); final ParameterValue<String> tileSize = AbstractGridFormat.SUGGESTED_TILE_SIZE.createValue(); tileSize.setValue("128,128"); // specify time final ParameterValue<List> time = ImageMosaicFormat.TIME.createValue(); final SimpleDateFormat formatD = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); formatD.setTimeZone(TimeZone.getTimeZone("GMT")); final Date timeD = formatD.parse("2012-01-01T00:00:00.000Z"); time.setValue(new ArrayList() { { add(timeD); } }); // specify additional Dimensions Set<ParameterDescriptor<List>> params = reader.getDynamicParameters(); ParameterValue<List<String>> polariz = null; for (ParameterDescriptor param : params) { if (param.getName().getCode().equalsIgnoreCase("POLARIZATION")) { polariz = param.createValue(); polariz.setValue(new ArrayList<String>() { { add("HH"); add("HV"); add("VV"); } }); } } // Stacked bands final ParameterValue<String> paramStacked = ImageMosaicFormat.MERGE_BEHAVIOR.createValue(); paramStacked.setValue(MergeBehavior.STACK.toString()); // Test the output coverage GeneralParameterValue[] values = new GeneralParameterValue[] { useJai, tileSize, time, polariz, paramStacked }; final GridCoverage2D coverage = TestUtils.getCoverage(reader, values, false); assertNotNull(coverage); // inspect reanderedImage final RenderedImage image = coverage.getRenderedImage(); assertEquals("wrong number of bands detected", 3, image.getSampleModel().getNumBands()); assertEquals(DataBuffer.TYPE_SHORT, image.getSampleModel().getDataType()); // ImageIO.write(image, "TIFF", new File("C:\\test.tif")); }
From source file:org.geotools.gce.imagemosaic.RasterLayerResponse.java
private RenderedImage processGranuleRaster(RenderedImage granule, final int granuleIndex, final int[] alphaIndex, final boolean alphaIn, final PlanarImage[] alphaChannels, final boolean doTransparentColor, final Color transparentColor) { ///* w w w .j av a 2s . com*/ // INDEX COLOR MODEL EXPANSION // // Take into account the need for an expansions of the original color // model. // // If the original color model is an index color model an expansion // might be requested in case the different palettes are not all the // same. In this case the mosaic operator from JAI would provide wrong // results since it would take the first palette and use that one for // all the other images. // // There is a special case to take into account here. In case the input // images use an IndexColorModel it might happen that the transparent // color is present in some of them while it is not present in some // others. This case is the case where for sure a color expansion is // needed. However we have to take into account that during the masking // phase the images where the requested transparent color was present // will have 4 bands, the other 3. If we want the mosaic to work we // have to add an extra band to the latter type of images for providing // alpha information to them. // // if (rasterManager.expandMe && granule.getColorModel() instanceof IndexColorModel) { granule = new ImageWorker(granule).forceComponentColorModel().getRenderedImage(); } // // TRANSPARENT COLOR MANAGEMENT // if (doTransparentColor) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine("Support for alpha on input image number " + granuleIndex); granule = ImageUtilities.maskColor(transparentColor, granule); alphaIndex[0] = granule.getColorModel().getNumComponents() - 1; } // // ROI // if (alphaIn || doTransparentColor) { ImageWorker w = new ImageWorker(granule); if (granule.getSampleModel() instanceof MultiPixelPackedSampleModel) w.forceComponentColorModel(); // // ALPHA in INPUT // // I have to select the alpha band and provide it to the final // mosaic operator. I have to force going to ComponentColorModel in // case the image is indexed. // if (granule.getColorModel() instanceof IndexColorModel) { alphaChannels[granuleIndex] = w.forceComponentColorModel().retainLastBand().getPlanarImage(); } else alphaChannels[granuleIndex] = w.retainBands(alphaIndex).getPlanarImage(); } return granule; }