private static void copyBandData(Mask[] selectedMasks, Product targetProduct) { for (Mask mask : selectedMasks) { Band band = createBandCopy(targetProduct, mask); band.setSourceImage(mask.getSourceImage()); } }
private static void reprojectBandData(Mask[] selectedMasks, Product sourceProduct, Product targetProduct) { final Map<String, Object> projParameters = Collections.emptyMap(); Map<String, Product> projProducts = new HashMap<>(); projProducts.put("source", sourceProduct); projProducts.put("collocateWith", targetProduct); Product reprojectedProduct = GPF.createProduct("Reproject", projParameters, projProducts); for (Mask mask : selectedMasks) { Band band = createBandCopy(targetProduct, mask); MultiLevelImage image = reprojectedProduct.getMaskGroup().get(mask.getName()).getSourceImage(); band.setSourceImage(image); } }
private void afterProcessedLastTile(Band targetBand, Tile targetTile, ProgressMonitor pm, int tileRowIndex, int tileColumnIndex) throws Exception { this.segmenter = this.tileSegmenter.runSecondSegmentationsAndMergeGraphs(); OutputMaskMatrixHelper outputMaskMatrixHelper = this.segmenter.buildOutputMaskMatrixHelper(); OutputMarkerMatrixHelper outputMarkerMatrix = outputMaskMatrixHelper.buildMaskMatrix(); outputMaskMatrixHelper.doClose(); WeakReference<OutputMaskMatrixHelper> referenceMaskMatrix = new WeakReference<OutputMaskMatrixHelper>(outputMaskMatrixHelper); referenceMaskMatrix.clear(); ProductData data = outputMarkerMatrix.buildOutputProductData(); int graphNodeCount = outputMarkerMatrix.getGraphNodeCount(); outputMarkerMatrix.doClose(); WeakReference<OutputMarkerMatrixHelper> referenceMarkerMatrix = new WeakReference<OutputMarkerMatrixHelper>(outputMarkerMatrix); referenceMarkerMatrix.clear(); Band productTargetBand = this.targetProduct.getBandAt(0); productTargetBand.setSourceImage(null); // reset the source image productTargetBand.setData(data); productTargetBand.getSourceImage(); if (logger.isLoggable(Level.FINE)) { int imageWidth = tileSegmenter.getImageWidth(); int imageHeight = tileSegmenter.getImageHeight(); int tileWidth = tileSegmenter.getTileWidth(); int tileHeight = tileSegmenter.getTileHeight(); int tileMargin = tileSegmenter.computeTileMargin(); long finishTime = System.currentTimeMillis(); long totalSeconds = (finishTime - this.startTime) / 1000; logger.log(Level.FINE, ""); // add an empty line logger.log(Level.FINE, "Finish Segmentation: image width: " + imageWidth + ", image height: " + imageHeight + ", tile width: " + tileWidth + ", tile height: " + tileHeight + ", margin: " + tileMargin + ", graph node count: " + graphNodeCount + ", total seconds: " + totalSeconds + ", finish time: " + new Date(finishTime)); } }
public static void replaceMeanAnglesBand(ArrayList<S2BandConstants> listOfBands, Product sourceProduct) { BandMathsOp.BandDescriptor bandDescriptorZenith = new BandMathsOp.BandDescriptor(); bandDescriptorZenith.name = "view_zenith_mean"; bandDescriptorZenith.expression = ""; for(S2BandConstants bandConstant : listOfBands) { bandDescriptorZenith.expression = bandDescriptorZenith.expression + String.format("view_zenith_%s +",bandConstant.getPhysicalName()); } bandDescriptorZenith.expression = String.format("(%s)/%d", (bandDescriptorZenith.expression).substring(0,(bandDescriptorZenith.expression).lastIndexOf('+')-1), listOfBands.size()); bandDescriptorZenith.type = ProductData.TYPESTRING_FLOAT32; BandMathsOp bandMathsOpZenith = new BandMathsOp(); bandMathsOpZenith.setParameterDefaultValues(); bandMathsOpZenith.setSourceProduct(sourceProduct); bandMathsOpZenith.setTargetBandDescriptors(bandDescriptorZenith); sourceProduct.getBand(bandDescriptorZenith.name).setSourceImage(bandMathsOpZenith.getTargetProduct().getBandAt(0).getSourceImage()); BandMathsOp.BandDescriptor bandDescriptorAzimuth = new BandMathsOp.BandDescriptor(); bandDescriptorAzimuth.name = "view_azimuth_mean"; bandDescriptorAzimuth.expression = ""; for(S2BandConstants bandConstant : listOfBands) { bandDescriptorAzimuth.expression = bandDescriptorAzimuth.expression + String.format("view_azimuth_%s +",bandConstant.getPhysicalName()); } bandDescriptorAzimuth.expression = String.format("(%s)/%d", (bandDescriptorAzimuth.expression).substring(0,(bandDescriptorAzimuth.expression).lastIndexOf('+')-1), listOfBands.size()); bandDescriptorAzimuth.type = ProductData.TYPESTRING_FLOAT32; BandMathsOp bandMathsOpAzimuth = new BandMathsOp(); bandMathsOpAzimuth.setParameterDefaultValues(); bandMathsOpAzimuth.setSourceProduct(sourceProduct); bandMathsOpAzimuth.setTargetBandDescriptors(bandDescriptorAzimuth); sourceProduct.getBand(bandDescriptorAzimuth.name).setSourceImage(bandMathsOpAzimuth.getTargetProduct().getBandAt(0).getSourceImage()); }
private void addDetectorBands(Product product, Map<String, L1BBandInfo> stringBandInfoMap, MultiLevelImageFactory mlif) throws IOException { product.setPreferredTileSize(S2Config.DEFAULT_JAI_TILE_SIZE, S2Config.DEFAULT_JAI_TILE_SIZE); product.setNumResolutionsMax(getConfig().getTileLayout(getProductResolution().resolution).numResolutions); product.setAutoGrouping("D01:D02:D03:D04:D05:D06:D07:D08:D09:D10:D11:D12"); ArrayList<String> bandIndexes = new ArrayList<>(stringBandInfoMap.keySet()); Collections.sort(bandIndexes); if (bandIndexes.isEmpty()) { throw new IOException("No valid bands found."); } for (String bandIndex : bandIndexes) { L1BBandInfo tileBandInfo = stringBandInfoMap.get(bandIndex); if (isMultiResolution() || tileBandInfo.getBandInformation().getResolution() == this.getProductResolution()) { TileLayout thisBandTileLayout = tileBandInfo.getImageLayout(); TileLayout productTileLayout = getConfig().getTileLayout(getProductResolution()); float factorX = (float) productTileLayout.width / thisBandTileLayout.width; float factorY = (float) productTileLayout.height / thisBandTileLayout.height; Dimension dimension = new Dimension(Math.round(product.getSceneRasterWidth() / factorX), Math.round(product.getSceneRasterHeight() / factorY)); Band band = addBand(product, tileBandInfo, dimension); band.setDescription(tileBandInfo.getBandInformation().getDescription()); band.setSourceImage(mlif.createSourceImage(tileBandInfo)); } } }
private void processSentinel2() { processLandWaterMask(); Map<String, Product> inputProducts = new HashMap<>(4); inputProducts.put("l1c", sourceProduct); inputProducts.put("waterMask", waterMaskProduct); final Map<String, Object> pixelClassificationParameters = createPixelClassificationParameters(); s2ClassifProduct = GPF.createProduct(OperatorSpi.getOperatorAlias(S2IdepixClassificationOp.class), pixelClassificationParameters, inputProducts); if (computeCloudShadow || computeCloudBuffer || computeMountainShadow) { // Post Cloud Classification: cloud shadow, cloud buffer, mountain shadow computePostProcessProduct(); targetProduct = S2IdepixUtils.cloneProduct(s2ClassifProduct, true); Band cloudFlagBand = targetProduct.getBand(S2IdepixUtils.IDEPIX_CLASSIF_FLAGS); cloudFlagBand.setSourceImage(postProcessingProduct.getBand(S2IdepixUtils.IDEPIX_CLASSIF_FLAGS).getSourceImage()); } else { targetProduct = s2ClassifProduct; } // new bit masks: S2IdepixUtils.setupIdepixCloudscreeningBitmasks(targetProduct); setTargetProduct(targetProduct); }
private void attachNewDimapReaderInstance(Product product, File newFile) throws IOException { DimapProductReader productReader = (DimapProductReader) ProductIO.getProductReader(DimapProductConstants.DIMAP_FORMAT_NAME); productReader.bindProduct(newFile, product); product.setProductReader(productReader); Band[] bands = product.getBands(); for (Band band : bands) { if (band.isSourceImageSet() && band.getSourceImage().getImage(0) instanceof BandOpImage) { band.setSourceImage(null); } } }
public static Product createProduct3() { int size = 10 * 1024; Product product = new Product("Test_Product_3", "Test_Type_3", size, size); product.setPreferredTileSize(512, 512); Band band1 = new Band("Big_Band_1", ProductData.TYPE_FLOAT64, product.getSceneRasterWidth(), product.getSceneRasterHeight()); Band band2 = new Band("Big_Band_2", ProductData.TYPE_FLOAT64, product.getSceneRasterWidth(), product.getSceneRasterHeight()); Band band3 = new Band("Big_Band_3", ProductData.TYPE_FLOAT64, product.getSceneRasterWidth(), product.getSceneRasterHeight()); Band band4 = new Band("Big_Band_4", ProductData.TYPE_FLOAT64, product.getSceneRasterWidth(), product.getSceneRasterHeight()); Band band5 = new Band("Big_Band_5", ProductData.TYPE_FLOAT64, product.getSceneRasterWidth(), product.getSceneRasterHeight()); band1.setSourceImage(ConstantDescriptor.create(1f * size, 1F * size, new Double[]{1.0}, null)); band2.setSourceImage(ConstantDescriptor.create(1f * size, 1F * size, new Double[]{2.0}, null)); band3.setSourceImage(ConstantDescriptor.create(1f * size, 1F * size, new Double[]{3.0}, null)); band4.setSourceImage(ConstantDescriptor.create(1f * size, 1F * size, new Double[]{4.0}, null)); band5.setSourceImage(ConstantDescriptor.create(1f * size, 1F * size, new Double[]{5.0}, null)); product.addBand(band1); product.addBand(band2); product.addBand(band3); product.addBand(band4); product.addBand(band5); product.setModified(true); double sx = 30.0 / product.getSceneRasterWidth(); AffineTransform at = new AffineTransform(); at.translate(100, 0.0); at.rotate(0.1, 15.0, 15.0); at.scale(sx, sx); product.setSceneGeoCoding(new ATGeoCoding(at)); return product; }
public static void replaceBandSourceImage(Band originalBand, PlanarImage planarImage) { MultiLevelImage newMultiLevelImage = new DefaultMultiLevelImage(new DefaultMultiLevelSource(planarImage, originalBand.getMultiLevelModel(), Interpolation.getInstance(Interpolation.INTERP_NEAREST))); originalBand.setSourceImage(S2ResamplerUtils.adjustImageToModelTransform(newMultiLevelImage, originalBand.getMultiLevelModel())); }
targetBand.setDescription(String.format("Ground reflectance without the correction of slope effects, band %s", bandId)); targetBand.setSourceImage(srcBand.getSourceImage());
private void addAOTImage(Product product, String pathString) { Band srcBand = getTifBand(pathString, 1); if (srcBand == null) { logger.warning(String.format("Image %s not added", pathString)); return; } MuscateMetadata.Geoposition geoposition = getGeoposition(srcBand.getRasterWidth(), srcBand.getRasterHeight()); if (geoposition == null) { logger.warning(String.format("Unrecognized geometry of image %s, it will not be added to the product %s.", pathString, product.getName())); return; } String bandName = "AOT_" + geoposition.id; Band targetBand = new Band(bandName, srcBand.getDataType(), srcBand.getRasterWidth(), srcBand.getRasterHeight()); product.addBand(targetBand); ProductUtils.copyGeoCoding(srcBand, targetBand); targetBand.setNoDataValue(metadata.getAOTNoDataValue()); targetBand.setNoDataValueUsed(true); targetBand.setScalingFactor(1.0d / metadata.getAOTQuantificationValue()); targetBand.setScalingOffset(0.0d); targetBand.setSampleCoding(srcBand.getSampleCoding()); targetBand.setImageInfo(srcBand.getImageInfo()); targetBand.setDescription(String.format("Aerosol Optical Thickness at %.0fm resolution", geoposition.xDim)); targetBand.setSourceImage(srcBand.getSourceImage()); }
private static void addElevationBand(Product product, ElevationModel dem, String elevationBandName) { final GeoCoding geoCoding = product.getSceneGeoCoding(); ElevationModelDescriptor demDescriptor = dem.getDescriptor(); final float noDataValue = dem.getDescriptor().getNoDataValue(); final Band elevationBand = product.addBand(elevationBandName, ProductData.TYPE_FLOAT32); elevationBand.setNoDataValueUsed(true); elevationBand.setNoDataValue(noDataValue); elevationBand.setUnit(Unit.METERS); elevationBand.setDescription(demDescriptor.getName()); elevationBand.setSourceImage(createElevationSourceImage(dem, geoCoding, elevationBand)); }
private void addWVCImage(Product product, String pathString) { Band srcBand = getTifBand(pathString, 0); if (srcBand == null) { logger.warning(String.format("Image %s not added", pathString)); return; } MuscateMetadata.Geoposition geoposition = getGeoposition(srcBand.getRasterWidth(), srcBand.getRasterHeight()); if (geoposition == null) { logger.warning(String.format("Unrecognized geometry of image %s, it will not be added to the product %s.", pathString, product.getName())); return; } String bandName = "WVC_" + geoposition.id; Band targetBand = new Band(bandName, srcBand.getDataType(), srcBand.getRasterWidth(), srcBand.getRasterHeight()); product.addBand(targetBand); ProductUtils.copyGeoCoding(srcBand, targetBand); targetBand.setNoDataValue(metadata.getWVCNoDataValue()); targetBand.setNoDataValueUsed(true); targetBand.setScalingFactor(1.0d / metadata.getWVCQuantificationValue()); targetBand.setScalingOffset(0.0d); targetBand.setUnit("cm"); //TODO verify targetBand.setSampleCoding(srcBand.getSampleCoding()); targetBand.setImageInfo(srcBand.getImageInfo()); targetBand.setDescription(String.format("Water vapor content at %.0fm resolution in %s", geoposition.xDim, targetBand.getUnit())); targetBand.setSourceImage(srcBand.getSourceImage()); }
targetBand.setImageInfo(srcBand.getImageInfo()); targetBand.setDescription("Edge mask"); targetBand.setSourceImage(srcBand.getSourceImage());
private Band addBand(final Product product, String name, final int w, final int h, final ImageIOFile img, final int bandIndex, final String unit) throws IOException { File bandFile = getFile(img.getName()); ProductReader reader = geotiffPlugIn.createReaderInstance(); Product bandProduct = reader.readProductNodes(bandFile, null); if (bandProduct != null) { bandProducts.add(bandProduct); Band srcBand = bandProduct.getBandAt(bandIndex); if (product.containsBand(name)) { name += "2"; } Band band = new Band(name, srcBand.getDataType(), w, h); band.setNoDataValue(0); band.setNoDataValueUsed(true); band.setUnit(unit); band.setSourceImage(srcBand.getSourceImage()); product.addBand(band); return band; } return null; }
public void updateSolarAngles(Product multiSizeProduct, Product targetProduct) { String azimuthBandName = "sun_azimuth"; String zenithBandName = "sun_zenith"; Band bandZenith = targetProduct.getBand(zenithBandName); Band bandAzimuth = targetProduct.getBand(azimuthBandName); S2BandAnglesGrid[] anglesGrid = ((S2AnglesGeometry)multiSizeProduct.getProductReader()).getSunAnglesGrid(); float[] extendedZenithData = S2ResamplerUtils.extendDataV2(anglesGrid[0].getData(), anglesGrid[0].getWidth(), anglesGrid[0].getHeight()); float[] extendedAzimuthData = S2ResamplerUtils.extendDataV2(anglesGrid[1].getData(), anglesGrid[1].getWidth(), anglesGrid[1].getHeight()); int extendedWidth = anglesGrid[0].getWidth() + 2; int extendedHeight = anglesGrid[0].getHeight() + 2; AffineTransform originalAffineTransform5000 = new AffineTransform(anglesGrid[0].getResX(), 0.0f, 0.0f, -anglesGrid[0].getResX(), anglesGrid[0].originX, anglesGrid[0].originY); AffineTransform extendedAffineTransform5000 = (AffineTransform) originalAffineTransform5000.clone(); extendedAffineTransform5000.translate(-1d,-1d); MultiLevelImage zenithMultiLevelImage = S2ResamplerUtils.createMultiLevelImage(extendedZenithData,extendedWidth,extendedHeight,extendedAffineTransform5000); MultiLevelImage targetImageZenith = S2ResamplerUtils.createInterpolatedImage(zenithMultiLevelImage, 0.0f, extendedAffineTransform5000, referenceWidth, referenceHeight, referenceTileSize, referenceMultiLevelModel, S2ResamplerUtils.getInterpolation("Bilinear")); MultiLevelImage azimuthMultiLevelImage = S2ResamplerUtils.createMultiLevelImage(extendedAzimuthData,extendedWidth,extendedHeight,extendedAffineTransform5000); MultiLevelImage targetImageAzimuth = S2ResamplerUtils.createInterpolatedImage(azimuthMultiLevelImage, 0.0f, extendedAffineTransform5000, referenceWidth, referenceHeight, referenceTileSize, referenceMultiLevelModel, S2ResamplerUtils.getInterpolation("Bilinear")); bandZenith.setSourceImage(S2ResamplerUtils.adjustImageToModelTransform(targetImageZenith, referenceMultiLevelModel)); bandAzimuth.setSourceImage(S2ResamplerUtils.adjustImageToModelTransform(targetImageAzimuth, referenceMultiLevelModel)); }
b.setScalingFactor(1.0 / 255.0); c.setScalingFactor(1.0 / 255.0); a.setSourceImage(new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY)); b.setSourceImage(new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY)); c.setSourceImage(new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY)); for (int i = 0; i < colors.length; i++) { String expression = "B > " + (i / (colors.length - 1.0));
protected void readMasks() { File file; if (metadata != null) { try { String maskFileName = metadata.getMaskFileName(); if (maskFileName != null) { file = productDirectory.getFile(maskFileName); if (file != null && file.exists()) { GeoTiffProductReader reader = new GeoTiffProductReader(getReaderPlugIn()); Product udmProduct = reader.readProductNodes(file, null); Band srcBand = udmProduct.getBandAt(0); float scaleX = (float)metadata.getRasterWidth() / (float)udmProduct.getSceneRasterWidth(); float scaleY = (float)metadata.getRasterHeight() / (float)udmProduct.getSceneRasterHeight(); RenderedOp renderedOp = ScaleDescriptor.create(srcBand.getSourceImage(), scaleX, scaleY, 0.0f, 0.0f, Interpolation.getInstance(Interpolation.INTERP_NEAREST), null); Band targetBand = product.addBand("unusable_data", srcBand.getDataType()); targetBand.setSourceImage(renderedOp); FlagCoding cloudsFlagCoding = createFlagCoding(product); targetBand.setSampleCoding(cloudsFlagCoding); List<Mask> cloudsMasks = createMasksFromFlagCodding(product, cloudsFlagCoding); for (Mask mask : cloudsMasks) { product.getMaskGroup().add(mask); } } } } catch (IOException e) { logger.warning(e.getMessage()); } } }
Product.findImageToModelTransform(band.getGeoCoding())); band.setSourceImage(mlif.createSourceImage(bandInfo));
private Band createTargetBand(int levels,String[] bandNames, int index, HashMap<Product, String> tiles, TileComponent tileComp) { Band targetBand = new Band(bandNames[index], this.bandDataType, tileComp.getNumColumns(), tileComp.getNumRows()); Band band = setInputSpecificationBand(tiles, index); final Dimension tileSize = JAIUtils.computePreferredTileSize(band.getRasterWidth(), band.getRasterHeight(), 1); setBandProperties(targetBand, band); initBandsGeoCoding(targetBand,tileComp); Map<Band, String> srcBands = getBandTiles(tiles, index); MosaicMultiLevelSource bandSource = new MosaicMultiLevelSource(srcBands, targetBand.getRasterWidth(), targetBand.getRasterHeight(), tileSize.width, tileSize.height, levels,tileComp, targetBand.getGeoCoding() != null ? Product.findImageToModelTransform(targetBand.getGeoCoding()) : Product.findImageToModelTransform(product.getSceneGeoCoding())); targetBand.setSourceImage(new DefaultMultiLevelImage(bandSource)); return targetBand; }