private void addGMLMasks(Product target, ImageMetadata metadata) { List<ImageMetadata.MaskInfo> gmlMasks = metadata.getMasks(); final Iterator<Color> colorIterator = ColorIterator.create(); Band refBand = findReferenceBand(target, metadata.getRasterWidth()); boolean isMultiSize = this.metadata.getImageMetadataList().size() > 1; gmlMasks.stream().forEach(mask -> { logger.info(String.format("Parsing mask %s of component %s", mask.name, metadata.getFileName())); VectorDataNode node = GMLReader.parse(mask.name, mask.path); if (node != null && node.getFeatureCollection().size() > 0) { node.setOwner(target); String maskName = mask.name; if (isMultiSize) { String resolution = "_" + new DecimalFormat("#.#").format(metadata.getPixelSize()) + "m"; maskName += resolution.endsWith(".") ? resolution.substring(0, resolution.length() - 1) : resolution; } if (refBand != null) { target.addMask(maskName, node, mask.description, colorIterator.next(), 0.5, refBand); } else { target.addMask(mask.name, node, mask.description, colorIterator.next(), 0.5); } } }); }
private void addGMLMasks(Product target, ImageMetadata metadata) { List<ImageMetadata.MaskInfo> gmlMasks = metadata.getMasks(); final Iterator<Color> colorIterator = ColorIterator.create(); Band refBand = findReferenceBand(target, metadata.getRasterWidth()); boolean isMultiSize = this.metadata.getImageMetadataList().size() > 1; gmlMasks.stream().forEach(mask -> { logger.info(String.format("Parsing mask %s of component %s", mask.name, metadata.getFileName())); VectorDataNode node = GMLReader.parse(mask.name, mask.path); if (node != null && node.getFeatureCollection().size() > 0) { node.setOwner(target); String maskName = mask.name; if (isMultiSize) { String resolution = "_" + new DecimalFormat("#.#").format(metadata.getPixelSize()) + "m"; maskName += resolution.endsWith(".") ? resolution.substring(0, resolution.length() - 1) : resolution; } if (refBand != null) { target.addMask(maskName, node, mask.description, colorIterator.next(), 0.5, refBand); } else { target.addMask(mask.name, node, mask.description, colorIterator.next(), 0.5); } } }); }
private Mask addMask(Product product, RasterDataNode raster, String expression) { Mask mask = Mask.BandMathsType.create(maskName, maskDescription, raster.getRasterWidth(), raster.getRasterHeight(), expression, maskColor, 0.5); product.addMask(mask); ProductUtils.copyImageGeometry(raster, mask, false); return mask; }
private void importMaskFromBmd(File file) { final PropertyMap propertyMap = new DefaultPropertyMap(); try { propertyMap.load(file.toPath()); // Overwrite existing values final String name = propertyMap.getPropertyString("bitmaskName", "bitmask"); final String description = propertyMap.getPropertyString("bitmaskDesc", null); final String expression = propertyMap.getPropertyString("bitmaskExpr", ""); final Color color = propertyMap.getPropertyColor("bitmaskColor", Color.yellow); final double transparency = propertyMap.getPropertyDouble("bitmaskTransparency", 0.5); final Product product = getMaskForm().getProduct(); product.addMask(name, expression, description, color, transparency); } catch (Exception e) { showErrorDialog(String.format("Failed to import mask(s): %s", e.getMessage())); } }
private void addIndexMasks(Product product, List<BandInfo> bandInfoList, Map<S2SpatialResolution,Dimension> sceneDimensions) throws IOException { for (BandInfo bandInfo : bandInfoList) { if (bandInfo.getBandInformation() instanceof S2IndexBandInformation) { S2IndexBandInformation indexBandInformation = (S2IndexBandInformation) bandInfo.getBandInformation(); IndexCoding indexCoding = indexBandInformation.getIndexCoding(); product.getIndexCodingGroup().add(indexCoding); List<Color> colors = indexBandInformation.getColors(); Iterator<Color> colorIterator = colors.iterator(); for (String indexName : indexCoding.getIndexNames()) { int indexValue = indexCoding.getIndexValue(indexName); String description = indexCoding.getIndex(indexName).getDescription(); if (!colorIterator.hasNext()) { // we should never be here : programming error. throw new IOException(String.format("Unexpected error when creating index masks : colors list does not have the same size as index coding")); } Color color = colorIterator.next(); Mask mask = Mask.BandMathsType.create(indexBandInformation.getPrefix() + indexName.toLowerCase(), description, sceneDimensions.get(bandInfo.getBandInformation().getResolution()).width, sceneDimensions.get(bandInfo.getBandInformation().getResolution()).height, String.format("%s.raw == %d", indexBandInformation.getPhysicalBand(), indexValue), color, 0.5); product.addMask(mask); } } } }
public static Product createProduct1() { Product product = new Product("Test_Product_1", "Test_Type_1", 2048, 1024); product.addTiePointGrid(new TiePointGrid("Grid_A", 32, 16, 0, 0, 2048f / 32, 1024f / 16, createRandomPoints(32 * 16))); product.addTiePointGrid(new TiePointGrid("Grid_B", 32, 16, 0, 0, 2048f / 32, 1024f / 16, createRandomPoints(32 * 16))); product.addBand("Band_A", "sin(4 * PI * sqrt( sq(X/1000.0 - 1) + sq(Y/500.0 - 1) ))"); product.addBand("Band_B", "sin(4 * PI * sqrt( 2.0 * abs(X/1000.0 * Y/500.0) ))"); product.addMask("Mask_A", "Band_A > 0.5", "I am Mask A", Color.ORANGE, 0.5); product.addMask("Mask_B", "Band_B < 0.0", "I am Mask B", Color.RED, 0.5); product.getMetadataRoot().addElement(new MetadataElement("Global_Attributes")); product.getMetadataRoot().addElement(new MetadataElement("Local_Attributes")); product.setModified(false); double sx = 40.0 / product.getSceneRasterWidth(); AffineTransform at = new AffineTransform(); at.translate(-80, -30); at.rotate(0.3, 20.0, 10.0); at.scale(sx, sx); product.setSceneGeoCoding(new ATGeoCoding(at)); return product; }
static void setMagicWandMask(Product product, String expression) { String validMaskExpression; try { validMaskExpression = BandArithmetic.getValidMaskExpression(expression, product, null); } catch (ParseException e) { validMaskExpression = null; } if (validMaskExpression != null) { expression = "(" + validMaskExpression + ") && (" + expression + ")"; } final Mask magicWandMask = product.getMaskGroup().get(MAGIC_WAND_MASK_NAME); if (magicWandMask != null) { magicWandMask.getImageConfig().setValue("expression", expression); } else { product.addMask(MAGIC_WAND_MASK_NAME, expression, "Magic wand mask", Color.RED, 0.5); } }
0.5); ProductUtils.copyGeoCoding(srcBand, mask0); product.addMask(mask0); 0.5); ProductUtils.copyGeoCoding(srcBand, mask1); product.addMask(mask1); 0.5); ProductUtils.copyGeoCoding(srcBand, mask2); product.addMask(mask2); 0.5); ProductUtils.copyGeoCoding(srcBand, mask3); product.addMask(mask3); 0.5); ProductUtils.copyGeoCoding(srcBand, mask4); product.addMask(mask4); 0.5); ProductUtils.copyGeoCoding(srcBand, mask5); product.addMask(mask5); 0.5); ProductUtils.copyGeoCoding(srcBand, mask6); product.addMask(mask6); 0.5);
product.addMask(mask);
0.5); ProductUtils.copyGeoCoding(srcBand, mask); product.addMask(mask);
0.5); ProductUtils.copyGeoCoding(srcBand, mask); product.addMask(mask);
0.5); ProductUtils.copyGeoCoding(srcBand, mask); product.addMask(mask);
0.5); ProductUtils.copyGeoCoding(srcBand, mask); product.addMask(mask);
0.5); ProductUtils.copyGeoCoding(srcBand, mask); product.addMask(mask); bitCount++;
public static Product createProduct2() { Product product = new Product("Test_Product_2", "Test_Type_2", 1024, 2048); product.addTiePointGrid(new TiePointGrid("Grid_1", 16, 32, 0, 0, 1024f / 16, 2048f / 32, createRandomPoints(32 * 16))); product.addTiePointGrid(new TiePointGrid("Grid_2", 16, 32, 0, 0, 1024f / 16, 2048f / 32, createRandomPoints(32 * 16))); product.addBand("Band_1", "cos(X/100)-sin(Y/100)"); product.addBand("Band_2", "sin(X/100)+cos(Y/100)"); product.addBand("Band_3", "cos(X/100)*cos(Y/100)"); product.addBand("Band_1_Unc", "cos(3*X/100)-sin(3*Y/100)"); product.addBand("Band_2_Unc", "sin(3*X/100)+cos(3*Y/100)"); product.addBand("Band_3_Unc", "cos(3*X/100)*cos(3*Y/100)"); product.getBand("Band_1").addAncillaryVariable(product.getBand("Band_1_Unc"), "uncertainty"); product.getBand("Band_2").addAncillaryVariable(product.getBand("Band_2_Unc"), "uncertainty"); product.getBand("Band_3").addAncillaryVariable(product.getBand("Band_3_Unc"), "uncertainty"); product.addMask("Mask_1", "Band_1 > 0.5", "I am Mask 1", Color.GREEN, 0.5); product.addMask("Mask_2", "Band_2 < 0.0", "I am Mask 2", Color.CYAN, 0.5); product.addMask("Mask_3", "Band_3 > -0.1 && Band_3 < 0.1", "I am Mask 3", Color.BLUE, 0.5); product.getMetadataRoot().addElement(new MetadataElement("Global_Attributes")); product.getMetadataRoot().addElement(new MetadataElement("Local_Attributes")); product.setModified(false); double sx = 20.0 / product.getSceneRasterWidth(); AffineTransform at = new AffineTransform(); at.scale(sx, sx); at.rotate(-0.2, 10.0, 10.0); product.setSceneGeoCoding(new ATGeoCoding(at)); product.addBand("A", "Band_1"); product.addBand("B", "Band_1 + Band_2 + Band_3"); product.addBand("C", "Band_1 / (2.3 + Band_2 + Band_3)"); product.addBand("D", "pow(Band_1, 3) / (pow(Band_1, 3) + pow(Band_3, 3))"); return product; }
private static Band createBandCopy(Product targetProduct, Mask mask) { String bandName = ProductUtils.getAvailableNodeName("mask_" + mask.getName(), targetProduct.getBandGroup()); String maskName = ProductUtils.getAvailableNodeName(mask.getName(), targetProduct.getMaskGroup()); int dataType = mask.getDataType(); Band band = targetProduct.addBand(bandName, dataType); String description = mask.getDescription() + " (from " + mask.getProduct().getDisplayName() + ")"; targetProduct.addMask(maskName, bandName, description, mask.getImageColor(), mask.getImageTransparency()); return band; }
targetProduct.getSceneRasterHeight(), expression, sourceMask.getImageColor(), sourceMask.getImageTransparency()); targetProduct.addMask(targetMask); } else if (imageType.getName().equals(Mask.VectorDataType.TYPE_NAME)) { VectorDataNode vectorDataMaskNode = Mask.VectorDataType.getVectorData(sourceMask); VectorDataNode targetVectorDataNode = transferVectorDataNode(targetProduct, vectorDataMaskNode, referenceImageToModelTransform); if (targetVectorDataNode != null) { targetProduct.addMask(sourceMask.getName(), targetVectorDataNode, sourceMask.getDescription(), sourceMask.getImageColor(), sourceMask.getImageTransparency());
tp.addMask(maskName, String.format("%s.%s", flagBandName, flagDef.getName()), flagDef.getDescription(),
targetProduct.addMask(maskDescriptor.name, maskDescriptor.expression, maskDescriptor.description, maskDescriptor.color, maskDescriptor.transparency);
contextProduct.addMask(maskName, mask.getImageType());