private static ImageInfo createIndexedImageInfo(Product product, Band band, IndexColorModel colorModel) { final IndexCoding indexCoding = new IndexCoding("color_map"); final int colorCount = colorModel.getMapSize(); final ColorPaletteDef.Point[] points = new ColorPaletteDef.Point[colorCount]; for (int j = 0; j < colorCount; j++) { final String name = String.format("I%3d", j); indexCoding.addIndex(name, j, ""); points[j] = new ColorPaletteDef.Point(j, new Color(colorModel.getRGB(j)), name); } product.getIndexCodingGroup().add(indexCoding); band.setSampleCoding(indexCoding); return new ImageInfo(new ColorPaletteDef(points, points.length)); }
private static ImageInfo createIndexedImageInfo(Product product, TIFFRenderedImage baseImage, Band band) { final IndexColorModel colorModel = (IndexColorModel) baseImage.getColorModel(); final IndexCoding indexCoding = new IndexCoding("color_map"); final int colorCount = colorModel.getMapSize(); final ColorPaletteDef.Point[] points = new ColorPaletteDef.Point[colorCount]; for (int j = 0; j < colorCount; j++) { final String name = String.format("I%3d", j); indexCoding.addIndex(name, j, ""); points[j] = new ColorPaletteDef.Point(j, new Color(colorModel.getRGB(j)), name); } product.getIndexCodingGroup().add(indexCoding); band.setSampleCoding(indexCoding); return new ImageInfo(new ColorPaletteDef(points, points.length)); }
public void testIndexCoding() { final IndexCoding ic = new IndexCoding("IC"); ic.addIndex("I1", 100, ""); ic.addIndex("I2", 300, ""); assertEquals(2, ic.getNumAttributes()); assertEquals(100, ic.getIndexValue("I1")); assertEquals(300, ic.getIndexValue("I2")); testIntValuesAllowedOnly(ic); testScalarValuesAllowedOnly(ic); }
private void attachIndexCodedBand() { final Band band = createDataBand(0, 1, INDEX_CODED_BAND_NAME); final IndexCoding indexCoding = new IndexCoding(INDEX_CODING_NAME); indexCoding.addIndex("i0", 0, "i0"); indexCoding.addIndex("i1", 1, "i1"); band.setSampleCoding(indexCoding); ColorPaletteDef.Point[] points = new ColorPaletteDef.Point[2]; points[0] = new ColorPaletteDef.Point(0, Color.RED); points[1] = new ColorPaletteDef.Point(1, Color.GREEN); ColorPaletteDef colors = new ColorPaletteDef(points); band.setImageInfo(new ImageInfo(colors)); product.getIndexCodingGroup().add(indexCoding); product.addBand(band); }
@Test public void testWriteReadIndexCodingSingle8BitBand() throws IOException { outProduct.removeBand(outProduct.getBandAt(0)); final Band bandUInt8 = outProduct.addBand("uint8", ProductData.TYPE_UINT8); bandUInt8.setDataElems(createByteData(getProductSize(), 23)); ImageManager.getInstance().getSourceImage(bandUInt8, 0); setTiePointGeoCoding(outProduct); final IndexCoding indexCoding = new IndexCoding("color_map"); indexCoding.addIndex("i1", 23, ""); indexCoding.addIndex("i2", 24, ""); indexCoding.addIndex("i3", 27, ""); indexCoding.addIndex("i4", 30, ""); outProduct.getBandAt(0).setSampleCoding(indexCoding); outProduct.getIndexCodingGroup().add(indexCoding); final Product inProduct = writeReadProduct(); assertEquals(1, inProduct.getIndexCodingGroup().getNodeCount()); final Band indexBand = inProduct.getBandAt(0); testIndexCoding(indexBand, 4); }
@Test public void testWriteReadIndexCodingWith2BandsBand() throws IOException { final Band bandUInt8 = outProduct.addBand("uint8", ProductData.TYPE_UINT8); bandUInt8.setDataElems(createByteData(getProductSize(), 20)); ImageManager.getInstance().getSourceImage(bandUInt8, 0); setTiePointGeoCoding(outProduct); final IndexCoding indexCoding = new IndexCoding("color_map"); indexCoding.addIndex("i1", 23, ""); indexCoding.addIndex("i2", 24, ""); indexCoding.addIndex("i3", 27, ""); indexCoding.addIndex("i4", 30, ""); outProduct.getIndexCodingGroup().add(indexCoding); outProduct.getBandAt(0).setSampleCoding(indexCoding); outProduct.getBandAt(1).setSampleCoding(indexCoding); final Product inProduct = writeReadProduct(); assertEquals(1, inProduct.getIndexCodingGroup().getNodeCount()); testIndexCoding(inProduct.getBandAt(0), 4); testIndexCoding(inProduct.getBandAt(1), 4); }
private void addSampleCodings(Product product) { String codingName1 = "FlagCoding1"; FlagCoding flagCoding1 = new FlagCoding(codingName1); flagCoding1.addFlag("Flag1A", 0, "Flag1A-Description"); flagCoding1.addFlag("Flag1B", 1, "Flag1B-Description"); flagCoding1.addFlag("Flag1C", 2, "Flag1C-Description"); product.getFlagCodingGroup().add(flagCoding1); // Add flag coding to band product.getBand("Flags1").setSampleCoding(product.getFlagCodingGroup().get(codingName1)); String codingName2 = "FlagCoding2"; FlagCoding flagCoding2 = new FlagCoding(codingName2); flagCoding2.addFlag("Flag2A", 5, "Flag2A-Description"); flagCoding2.addFlag("Flag2B", 6, "Flag2B-Description"); product.getFlagCodingGroup().add(flagCoding2); // Add flag coding to band product.getBand("Flags2").setSampleCoding(product.getFlagCodingGroup().get(codingName2)); String codingName3 = "IndexCoding"; IndexCoding indexCoding = new IndexCoding(codingName3); indexCoding.addIndex("Index1", 0, "Index1-Description"); indexCoding.addIndex("Index2", 1, "Index2-Description"); indexCoding.addIndex("Index3", 2, "Index3-Description"); product.getIndexCodingGroup().add(indexCoding); // Add flag coding to band product.getBand("Index").setSampleCoding(indexCoding); }
@Test public void testCopyIndexCoding() { final IndexCoding originalIndexCoding = new IndexCoding("sesame street characters"); originalIndexCoding.addIndex("erni", 0, "erni character"); originalIndexCoding.addIndex("bert", 1, "bert character"); final Product product = new Product("S", "S", 0, 0); ProductUtils.copyIndexCoding(originalIndexCoding, product); final ProductNodeGroup<IndexCoding> indexCodingGroup = product.getIndexCodingGroup(); assertNotNull(indexCodingGroup); assertEquals(1, indexCodingGroup.getNodeCount()); final IndexCoding actualIndexCoding = indexCodingGroup.get("sesame street characters"); assertNotNull(actualIndexCoding); assertNotSame(originalIndexCoding, actualIndexCoding); assertMetadataAttributeEqualityInt(originalIndexCoding.getIndex("erni"), actualIndexCoding.getIndex("erni")); assertMetadataAttributeEqualityInt(originalIndexCoding.getIndex("bert"), actualIndexCoding.getIndex("bert")); // try to copy the same coding a second time ProductUtils.copyIndexCoding(originalIndexCoding, product); assertEquals(1, indexCodingGroup.getNodeCount()); }
@Override public void initialize() throws OperatorException { collectSourceBands(); int width = sourceProduct.getSceneRasterWidth(); int height = sourceProduct.getSceneRasterHeight(); final String name = sourceProduct.getName() + "_CLUSTERS"; final String type = sourceProduct.getProductType() + "_CLUSTERS"; targetProduct = new Product(name, type, width, height); ProductUtils.copyTiePointGrids(sourceProduct, targetProduct); ProductUtils.copyGeoCoding(sourceProduct, targetProduct); targetProduct.setStartTime(sourceProduct.getStartTime()); targetProduct.setEndTime(sourceProduct.getEndTime()); clusterMapBand = new Band("class_indices", ProductData.TYPE_UINT8, width, height); clusterMapBand.setDescription("Class_indices"); clusterMapBand.setNoDataValue(NO_DATA_VALUE); clusterMapBand.setNoDataValueUsed(true); targetProduct.addBand(clusterMapBand); final IndexCoding indexCoding = new IndexCoding("Cluster_classes"); for (int i = 0; i < clusterCount; i++) { indexCoding.addIndex("class_" + (i + 1), i, "Cluster " + (i + 1)); } targetProduct.getIndexCodingGroup().add(indexCoding); clusterMapBand.setSampleCoding(indexCoding); clusterAnalysis = new MetadataElement("Cluster_Analysis"); targetProduct.getMetadataRoot().addElement(clusterAnalysis); setTargetProduct(targetProduct); }
indexCoding.addIndex("class_" + (i + 1), i, "Cluster " + (i + 1));
final IndexCoding indexCoding = new IndexCoding("classification"); for (int i = 0; i < numClasses; i++) { indexCoding.addIndex(classNames[i], i, "");