private ImageInfo createDeltaBandImageInfo(double p1, double p2) { return new ImageInfo(new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(p1, new Color(255, 0, 0)), new ColorPaletteDef.Point((p1 + p2) / 2, new Color(255, 255, 255)), new ColorPaletteDef.Point(p2, new Color(0, 0, 127)), })); } }
private void drawPalette(Graphics2D g2, ColorPaletteDef colorPaletteDef, Dimension paletteDim) { final int width = paletteDim.width; final int height = paletteDim.height; final ColorPaletteDef cpdCopy = colorPaletteDef.createDeepCopy(); cpdCopy.setDiscrete(discreteDisplay); cpdCopy.setNumColors(width); final ImageInfo imageInfo = new ImageInfo(cpdCopy); imageInfo.setLogScaled(log10Display); Color[] colorPalette = ImageManager.createColorPalette(imageInfo); g2.setStroke(new BasicStroke(1.0f)); for (int x = 0; x < width; x++) { g2.setColor(colorPalette[x]); g2.drawLine(x, 0, x, height); } }
@Override public ImageInfo createDefaultImageInfo(double[] histoSkipAreas, ProgressMonitor pm) { final IndexCoding indexCoding = getIndexCoding(); if (indexCoding == null) { return super.createDefaultImageInfo(histoSkipAreas, pm); } final int sampleCount = indexCoding.getSampleCount(); Random random = new Random(0xCAFEBABE); ColorPaletteDef.Point[] points = new ColorPaletteDef.Point[sampleCount]; for (int i = 0; i < sampleCount; i++) { String name = indexCoding.getSampleName(i); int value = indexCoding.getSampleValue(i); final Color color = new Color(random.nextFloat(), random.nextFloat(), random.nextFloat()); points[i] = new ColorPaletteDef.Point(value, color, name); } return new ImageInfo(new ColorPaletteDef(points, points.length)); }
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)); }
private static ImageInfo createImageInfo(Element bandStatisticsElem) { final ColorPaletteDef.Point[] points = getColorPalettePoints(bandStatisticsElem); final int numColors = getNumColors(bandStatisticsElem); final ImageInfo imageInfo = new ImageInfo(new ColorPaletteDef(points, numColors)); final Element noDataElem = bandStatisticsElem.getChild(DimapProductConstants.TAG_NO_DATA_COLOR); if (noDataElem != null) { imageInfo.setNoDataColor(createColor(noDataElem)); } final Element histomElem = bandStatisticsElem.getChild(DimapProductConstants.TAG_HISTOGRAM_MATCHING); if (histomElem != null && histomElem.getValue() != null) { imageInfo.setHistogramMatching(ImageInfo.getHistogramMatching(histomElem.getValue())); } return imageInfo; }
private static void readImageInfo(Variable variable, Band band) throws ProductIOException { final Attribute sampleValues = variable.findAttributeIgnoreCase(COLOR_TABLE_SAMPLE_VALUES); final Attribute redValues = variable.findAttributeIgnoreCase(COLOR_TABLE_RED_VALUES); final Attribute greenValues = variable.findAttributeIgnoreCase(COLOR_TABLE_GREEN_VALUES); final Attribute blueValues = variable.findAttributeIgnoreCase(COLOR_TABLE_BLUE_VALUES); final Attribute[] attributes = {sampleValues, redValues, greenValues, blueValues}; if (allAttributesAreNotNullAndHaveTheSameSize(attributes)) { final ColorPaletteDef.Point[] points = new ColorPaletteDef.Point[sampleValues.getLength()]; for (int i = 0; i < points.length; i++) { final int red = redValues.getNumericValue(i).intValue(); final int green = greenValues.getNumericValue(i).intValue(); final int blue = blueValues.getNumericValue(i).intValue(); final Color color = new Color(red, green, blue); points[i] = new ColorPaletteDef.Point(sampleValues.getNumericValue(i).doubleValue(), color); } band.setImageInfo(new ImageInfo(new ColorPaletteDef(points))); } }
private void attachColoredBand() { final Band band = createDataBand(0, 255, COLORED_BAND_NAME); ColorPaletteDef.Point[] points = new ColorPaletteDef.Point[2]; points[0] = new ColorPaletteDef.Point(128, Color.BLUE); points[1] = new ColorPaletteDef.Point(255, Color.BLACK); ColorPaletteDef colors = new ColorPaletteDef(points); band.setImageInfo(new ImageInfo(colors)); product.addBand(band); }
private ImageInfo createImageInfo() { ColorPaletteDef.Point[] points = new ColorPaletteDef.Point[3]; points[0] = new ColorPaletteDef.Point(0.1d, Color.black); //black = new Color( 0, 0, 0, 255) points[1] = new ColorPaletteDef.Point(1.3d, Color.cyan); //cyan = new Color( 0, 255, 255, 255) points[2] = new ColorPaletteDef.Point(2.8d, Color.white); //white = new Color(255, 255, 255, 255) ColorPaletteDef paleteDefinition = new ColorPaletteDef(points, 180); final ImageInfo imageInfo = new ImageInfo(paleteDefinition); imageInfo.setNoDataColor(Color.BLUE); imageInfo.setHistogramMatching(ImageInfo.HistogramMatching.Normalize); return imageInfo; }
@Test public void testCreateLinearColorPalette() { final ColorPaletteDef cpd = new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(100, Color.WHITE), new ColorPaletteDef.Point(200, Color.BLUE), new ColorPaletteDef.Point(300, Color.RED), new ColorPaletteDef.Point(400, Color.GREEN), }, 7); final ImageInfo imageInfo = new ImageInfo(cpd); imageInfo.setLogScaled(false); final Color[] palette = ImageManager.createColorPalette(imageInfo); assertNotNull(palette); assertEquals(7, palette.length); assertEquals(new Color(255, 255, 255), palette[0]); assertEquals(new Color(128, 128, 255), palette[1]); assertEquals(new Color(0, 0, 255), palette[2]); assertEquals(new Color(128, 0, 128), palette[3]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(128, 128, 0), palette[5]); assertEquals(new Color(0, 255, 0), palette[6]); }
@Test public void testCreateLog10ColorPalette() { final ColorPaletteDef cpd = new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(1, Color.WHITE), new ColorPaletteDef.Point(10, Color.BLUE), new ColorPaletteDef.Point(100, Color.RED), new ColorPaletteDef.Point(1000, Color.GREEN), }, 7); final ImageInfo imageInfo = new ImageInfo(cpd); imageInfo.setLogScaled(true); final Color[] palette = ImageManager.createColorPalette(imageInfo); assertNotNull(palette); assertEquals(7, palette.length); assertEquals(new Color(255, 255, 255), palette[0]); assertEquals(new Color(128, 128, 255), palette[1]); assertEquals(new Color(0, 0, 255), palette[2]); assertEquals(new Color(128, 0, 128), palette[3]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(128, 128, 0), palette[5]); assertEquals(new Color(0, 255, 0), palette[6]); }
@Test public void testCreateLog10ColorPalette_Discrete() { final ColorPaletteDef cpd = new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(1, Color.WHITE), new ColorPaletteDef.Point(10, Color.BLUE), new ColorPaletteDef.Point(100, Color.RED), new ColorPaletteDef.Point(1000, Color.GREEN), }, 7); cpd.setDiscrete(true); final ImageInfo imageInfo = new ImageInfo(cpd); imageInfo.setLogScaled(true); final Color[] palette = ImageManager.createColorPalette(imageInfo); assertNotNull(palette); assertEquals(7, palette.length); assertEquals(new Color(255, 255, 255), palette[0]); assertEquals(new Color(255, 255, 255), palette[1]); assertEquals(new Color(0, 0, 255), palette[2]); assertEquals(new Color(0, 0, 255), palette[3]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(255, 0, 0), palette[5]); assertEquals(new Color(0, 255, 0), palette[6]); } }
@Test public void testCreateLinearColorPalette_Discrete() { final ColorPaletteDef cpd = new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(100, Color.WHITE), new ColorPaletteDef.Point(200, Color.BLUE), new ColorPaletteDef.Point(300, Color.RED), new ColorPaletteDef.Point(400, Color.GREEN), }, 7); cpd.setDiscrete(true); final ImageInfo imageInfo = new ImageInfo(cpd); imageInfo.setLogScaled(false); final Color[] palette = ImageManager.createColorPalette(imageInfo); assertNotNull(palette); assertEquals(7, palette.length); assertEquals(new Color(255, 255, 255), palette[0]); assertEquals(new Color(255, 255, 255), palette[1]); assertEquals(new Color(0, 0, 255), palette[2]); assertEquals(new Color(0, 0, 255), palette[3]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(0, 255, 0), palette[6]); }
public void testSetAndGetBandStatistics() { RasterDataNode rasterDataNode = createRasterDataNode(); assertEquals(null, rasterDataNode.getImageInfo()); final ImageInfo imageInfo = new ImageInfo(new ColorPaletteDef(0, 1)); rasterDataNode.setImageInfo(imageInfo); assertSame(imageInfo, rasterDataNode.getImageInfo()); }
final ColorPaletteDef gradationCurve = new ColorPaletteDef(min, center, max); return new ImageInfo(gradationCurve);
public ImageInfo getImageInfo(RasterDataNode[] rasters) { Assert.notNull(rasters, "rasters"); Assert.argument(rasters.length == 1 || rasters.length == 3, "rasters.length == 1 || rasters.length == 3"); if (rasters.length == 1) { RasterDataNode raster = rasters[0]; Assert.state(raster.getImageInfo() != null, "raster.getImageInfo() != null"); return raster.getImageInfo(); } else { final RGBChannelDef rgbChannelDef = new RGBChannelDef(); for (int i = 0; i < rasters.length; i++) { RasterDataNode raster = rasters[i]; Assert.state(rasters[i].getImageInfo() != null, "rasters[i].getImageInfo() != null"); ImageInfo imageInfo = raster.getImageInfo(); rgbChannelDef.setSourceName(i, raster.getName()); rgbChannelDef.setMinDisplaySample(i, imageInfo.getColorPaletteDef().getMinDisplaySample()); rgbChannelDef.setMaxDisplaySample(i, imageInfo.getColorPaletteDef().getMaxDisplaySample()); } return new ImageInfo(rgbChannelDef); } }
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); }
rgbChannelDef.setMaxDisplaySample(i, imageInfo.getColorPaletteDef().getMaxDisplaySample()); return new ImageInfo(rgbChannelDef); } finally { pm.done();
public void testImageInfo3Bands() { final RGBChannelDef rgbcd = new RGBChannelDef(new String[]{ "radiance_13", "radiance_5", "radiance_2" }); ImageInfo imageInfo = new ImageInfo(rgbcd); assertEquals(null, imageInfo.getColorPaletteDef()); assertSame(rgbcd, imageInfo.getRgbChannelDef()); assertEquals(4, imageInfo.getColorComponentCount()); imageInfo.setNoDataColor(Color.RED); assertEquals(Color.RED, imageInfo.getNoDataColor()); assertEquals(3, imageInfo.getColorComponentCount()); imageInfo.setHistogramMatching(ImageInfo.HistogramMatching.Normalize); assertEquals(ImageInfo.HistogramMatching.Normalize, imageInfo.getHistogramMatching()); final RGBChannelDef rgbcdAlpha = new RGBChannelDef(new String[]{ "radiance_13", "radiance_5", "radiance_2", "50.0" }); imageInfo = new ImageInfo(rgbcdAlpha); assertEquals(4, imageInfo.getColorComponentCount()); imageInfo.setNoDataColor(Color.RED); assertEquals(4, imageInfo.getColorComponentCount()); } }
public void testImageInfo1Band() { final ColorPaletteDef cpd = new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(100, Color.ORANGE), new ColorPaletteDef.Point(200, Color.MAGENTA), new ColorPaletteDef.Point(500, Color.BLUE), new ColorPaletteDef.Point(600, Color.WHITE) }); ImageInfo imageInfo = new ImageInfo(cpd); assertSame(cpd, imageInfo.getColorPaletteDef()); assertEquals(null, imageInfo.getRgbChannelDef()); assertEquals(4, imageInfo.getColorComponentCount()); assertEquals(ImageInfo.NO_COLOR, imageInfo.getNoDataColor()); assertEquals(ImageInfo.HistogramMatching.None, imageInfo.getHistogramMatching()); assertNotNull(imageInfo.getColors()); assertEquals(4, imageInfo.getColors().length); assertEquals(Color.ORANGE, imageInfo.getColors()[0]); assertEquals(Color.MAGENTA, imageInfo.getColors()[1]); assertEquals(Color.BLUE, imageInfo.getColors()[2]); assertEquals(Color.WHITE, imageInfo.getColors()[3]); imageInfo.setNoDataColor(Color.RED); assertEquals(Color.RED, imageInfo.getNoDataColor()); assertEquals(3, imageInfo.getColorComponentCount()); imageInfo.setHistogramMatching(ImageInfo.HistogramMatching.Equalize); assertEquals(ImageInfo.HistogramMatching.Equalize, imageInfo.getHistogramMatching()); }