private static ColorPaletteDef.Point[] getColorPalettePoints(Element bandStatisticsElem) { final List colorPalettePointElems = bandStatisticsElem.getChildren( DimapProductConstants.TAG_COLOR_PALETTE_POINT); ColorPaletteDef.Point[] points = null; if (colorPalettePointElems.size() > 1) { final Iterator iteratorCPPE = colorPalettePointElems.iterator(); points = new ColorPaletteDef.Point[colorPalettePointElems.size()]; for (int i = 0; i < points.length; i++) { final Element colorPalettePointElem = (Element) iteratorCPPE.next(); final Color color = DimapProductHelpers.createColor( colorPalettePointElem.getChild(DimapProductConstants.TAG_COLOR)); final double sample = getSample(colorPalettePointElem); final String label = getLabel(colorPalettePointElem); points[i] = new ColorPaletteDef.Point(sample, color, label); } } return points; }
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)), })); } }
@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)); }
new Point(100, Color.ORANGE), new Point(200, Color.MAGENTA), new Point(500, Color.BLUE), new Point(600, Color.WHITE) }); assertEquals(4, cpd.getNumPoints()); new Point(100, Color.ORANGE), new Point(200, Color.MAGENTA), new Point(500, Color.BLUE), new Point(600, Color.WHITE) }, 512); assertEquals(4, cpd.getNumPoints());
/** * creates a new point between the point at the given index * * @param index the index * @param scaling the scaling * * @return true, if a point has been inserted */ public boolean createPointAfter(int index, Scaling scaling) { Point point1 = getPointAt(index); Point point2 = null; if (index < points.indexOf(points.lastElement())) { point2 = getPointAt(index + 1); } final Point newPoint; if (point2 != null) { final double max = Math.max(point1.getSample(), point2.getSample()); final double min = Math.min(point1.getSample(), point2.getSample()); final double middle; middle = scaling.scale(0.5 * (scaling.scaleInverse(min) + scaling.scaleInverse(max))); newPoint = new Point(middle, getCenterColor(point1.getColor(), point2.getColor())); insertPointAfter(index, newPoint); return true; } return false; }
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()); }
@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]); }
@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]); }
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))); } }
@Test public void testCreateClone_andEquals() { //preparation final Point[] points = { new Point(1, Color.black), new Point(2, Color.red), new Point(3, Color.green), new Point(4, Color.blue), new Point(5, Color.white), }; final ColorPaletteDef cpd = new ColorPaletteDef(points, 256); cpd.setDiscrete(true); cpd.setAutoDistribute(true); //execution final ColorPaletteDef clone = (ColorPaletteDef) cpd.clone(); //verification assertTrue(cpd.equals(clone)); }
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 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); }
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)); }
public void setNumPoints(int numPoints) { while (getNumPoints() < numPoints) { addPoint(new Point(getMaxDisplaySample() + 1.0, Color.BLACK)); } while (getNumPoints() > numPoints) { removePointAt(getNumPoints() - 1); } }
private static void alignNumPoints(ColorPaletteDef sourceCPD, ColorPaletteDef targetCPD) { int deltaNumPoints = targetCPD.getNumPoints() - sourceCPD.getNumPoints(); if (deltaNumPoints < 0) { for (; deltaNumPoints != 0; deltaNumPoints++) { targetCPD.insertPointAfter(0, new ColorPaletteDef.Point()); } } else if (deltaNumPoints > 0) { for (; deltaNumPoints != 0; deltaNumPoints--) { targetCPD.removePointAt(1); } } }
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; }
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); }