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 static void transferPoints(ColorPaletteDef sourceCPD, double minSample, double maxSample, boolean autoDistribute, ColorPaletteDef targetCPD) { if (autoDistribute || sourceCPD.isAutoDistribute()) { alignNumPoints(sourceCPD, targetCPD); double minDisplaySample = sourceCPD.getMinDisplaySample(); double maxDisplaySample = sourceCPD.getMaxDisplaySample(); double delta1 = (maxSample > minSample) ? maxSample - minSample : 1.0; double delta2 = (maxDisplaySample > minDisplaySample) ? maxDisplaySample - minDisplaySample : 1.0; double b = delta1 / delta2; double a = minSample - minDisplaySample * b; for (int i = 0; i < sourceCPD.getNumPoints(); i++) { targetCPD.getPointAt(i).setSample(a + b * sourceCPD.getPointAt(i).getSample()); targetCPD.getPointAt(i).setColor(sourceCPD.getPointAt(i).getColor()); targetCPD.getPointAt(i).setLabel(sourceCPD.getPointAt(i).getLabel()); } } else { targetCPD.setPoints(sourceCPD.getPoints().clone()); } }
public Color[] getColors() { return colorPaletteDef != null ? colorPaletteDef.getColors() : new Color[0]; }
public Point[] getPoints() { Point[] points = new Point[getNumPoints()]; for (int i = 0; i < getNumPoints(); i++) { points[i] = getPointAt(i); } return points; }
public Color computeColor(final Scaling scaling, final double sample) { // @todo 1 tb/tb take care of non-linear scalings 2014-03-26 return computeColor(sample, getMinDisplaySample(), getMaxDisplaySample()); }
public void setNumPoints(int numPoints) { while (getNumPoints() < numPoints) { addPoint(new Point(getMaxDisplaySample() + 1.0, Color.BLACK)); } while (getNumPoints() > numPoints) { removePointAt(getNumPoints() - 1); } }
@Test public void testConstructors() { ColorPaletteDef cpd = new ColorPaletteDef(-1.0, 1.0); assertEquals(256, cpd.getNumColors()); assertEquals(3, cpd.getNumPoints()); assertEquals(-1.0, cpd.getPointAt(0).getSample(), 1e-10); assertEquals(+0.0, cpd.getPointAt(1).getSample(), 1e-10); assertEquals(+1.0, cpd.getPointAt(2).getSample(), 1e-10); assertEquals(Color.BLACK, cpd.getPointAt(0).getColor()); assertEquals(Color.GRAY, cpd.getPointAt(1).getColor()); assertEquals(Color.WHITE, cpd.getPointAt(2).getColor()); cpd = new ColorPaletteDef(-1.0, 0.5, 1.0); assertEquals(256, cpd.getNumColors()); assertEquals(3, cpd.getNumPoints()); assertEquals(-1.0, cpd.getPointAt(0).getSample(), 1e-10); assertEquals(+0.5, cpd.getPointAt(1).getSample(), 1e-10); assertEquals(+1.0, cpd.getPointAt(2).getSample(), 1e-10); assertEquals(Color.BLACK, cpd.getPointAt(0).getColor()); assertEquals(Color.GRAY, cpd.getPointAt(1).getColor()); assertEquals(Color.WHITE, cpd.getPointAt(2).getColor()); cpd = new ColorPaletteDef(new Point[]{ new Point(100, Color.ORANGE), new Point(200, Color.MAGENTA), new Point(600, Color.WHITE) }); assertEquals(4, cpd.getNumPoints()); assertEquals(256, cpd.getNumColors());
private static PlanarImage createByteIndexedImage(RasterDataNode raster, RenderedImage sourceImage, ImageInfo imageInfo) { ColorPaletteDef colorPaletteDef = imageInfo.getColorPaletteDef(); final double minSample = colorPaletteDef.getMinDisplaySample(); final double maxSample = colorPaletteDef.getMaxDisplaySample(); if (isClassificationBand(raster)) { final IntMap sampleColorIndexMap = new IntMap((int) minSample - 1, 4098); final ColorPaletteDef.Point[] points = colorPaletteDef.getPoints(); for (int colorIndex = 0; colorIndex < points.length; colorIndex++) { sampleColorIndexMap.putValue((int) getSample(points[colorIndex]), colorIndex); } final int undefinedIndex = colorPaletteDef.getNumPoints(); return createIndexedImage(sourceImage, sampleColorIndexMap, undefinedIndex); } else { return createByteIndexedImage(raster, sourceImage, minSample, maxSample, 1.0); } }
private double normalizeSample(double sample) { double minDisplaySample = getImageInfo().getColorPaletteDef().getMinDisplaySample(); double maxDisplaySample = getImageInfo().getColorPaletteDef().getMaxDisplaySample(); if (imageInfo.isLogScaled()) { minDisplaySample = Math.log10(imageInfo.getColorPaletteDef().getMinDisplaySample()); maxDisplaySample = Math.log10(imageInfo.getColorPaletteDef().getMaxDisplaySample()); sample = Math.log10(sample); } double delta = maxDisplaySample - minDisplaySample; if (delta == 0 || Double.isNaN(delta)) { delta = 1; } return (sample - minDisplaySample) / delta; }
@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)); }
public static Color computeColor(ImageInfo imageInfo, Double rasterValue) { final ColorPaletteDef cpd = imageInfo.getColorPaletteDef(); if (rasterValue <= cpd.getMinDisplaySample()) { return cpd.getFirstPoint().getColor(); } else if (rasterValue >= cpd.getMaxDisplaySample()) { return cpd.getLastPoint().getColor(); } else { BorderSamplesAndColors boSaCo = new BorderSamplesAndColors(); final boolean logScaled = imageInfo.isLogScaled(); if (logScaled) { rasterValue = Stx.LOG10_SCALING.scale(rasterValue); } for (int i = 0; i < cpd.getNumPoints() - 1; i++) { boSaCo = getBorderSamplesAndColors(imageInfo, i, boSaCo); if (rasterValue >= boSaCo.sample1 && rasterValue <= boSaCo.sample2) { return computeColor(rasterValue, boSaCo); } } } return Color.black; }
@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]); }
final ColorPaletteDef cpd = imageInfo.getColorPaletteDef(); Debug.assertNotNull(cpd); Debug.assertTrue(cpd.getNumPoints() >= 2); minSample = getSampleLog(cpd.getFirstPoint()); maxSample = getSampleLog(cpd.getLastPoint()); } else { minSample = getSample(cpd.getFirstPoint()); maxSample = getSample(cpd.getLastPoint()); final int numColors = cpd.getNumColors(); final double scalingFactor = 1 / (numColors - 1.0); final Color[] colorPalette = new Color[numColors]; int pointIndex = 0; final int maxPointIndex = cpd.getNumPoints() - 2; BorderSamplesAndColors boSaCo = getBorderSamplesAndColors(imageInfo, pointIndex, null); for (int i = 0; i < numColors - 1; i++) { boSaCo = getBorderSamplesAndColors(imageInfo, pointIndex, boSaCo); if (cpd.isDiscrete()) { colorPalette[i] = boSaCo.color1; } else {
private ColorPaletteDef.Point getGradationCurvePointAt(int index) { return getImageInfo().getColorPaletteDef().getPointAt(index); }
final int numColorComponents = imageInfo.getColorComponentCount(); final byte[] rgbSamples = new byte[numColorComponents * numPixels]; final double minSample = imageInfo.getColorPaletteDef().getMinDisplaySample(); final double maxSample = imageInfo.getColorPaletteDef().getMaxDisplaySample(); } else { final IntMap sampleColorIndexMap = new IntMap((int) minSample - 1, 4098); final ColorPaletteDef.Point[] points = imageInfo.getColorPaletteDef().getPoints(); for (int colorIndex = 0; colorIndex < points.length; colorIndex++) { sampleColorIndexMap.putValue((int) points[colorIndex].getSample(), colorIndex);
static boolean checkApplicability(ColorPaletteDef cpd) { final ColorPaletteDef.Point[] points = cpd.getPoints(); for (ColorPaletteDef.Point point : points) { if (point.getSample() <= 0.0) { return false; } } return true; } }
final ImageInfo currentInfo = parentForm.getImageInfo(); final ColorPaletteDef currentCPD = currentInfo.getColorPaletteDef(); final ColorPaletteDef deepCopy = selectedCPD.createDeepCopy(); deepCopy.setDiscrete(currentCPD.isDiscrete()); break; default: min = currentCPD.getMinDisplaySample(); max = currentCPD.getMaxDisplaySample(); cpd = deepCopy;
public static void applyPaletteToRaster(ColorPaletteDef cpd, RasterDataNode raster) { removeRasterFromMapping(raster); final ImageInfo imageInfo = raster.getImageInfo(); if (imageInfo == null) { return; } final double minSample; final double maxSample; final boolean autoDistribute; final ColorPaletteDef oldDef = imageInfo.getColorPaletteDef(); if (oldDef != null) { minSample = oldDef.getMinDisplaySample(); maxSample = oldDef.getMaxDisplaySample(); autoDistribute = oldDef.isAutoDistribute(); } else { minSample = cpd.getMinDisplaySample(); maxSample = cpd.getMaxDisplaySample(); autoDistribute = cpd.isAutoDistribute(); } imageInfo.setColorPaletteDef(cpd.createDeepCopy(), minSample, maxSample, autoDistribute); appendRasterToMapping(cpd, raster); }
private void testPalette(ColorPaletteDef palette, Color[] colors) { assertEquals(colors.length, palette.getPoints().length); for (int i = 0; i < colors.length; i++) { assertEquals(colors[i], palette.getPointAt(i).getColor()); } }
private Color computeColor(final double sample) { for (int i = 0; i < getNumPoints() - 1; i++) { final Point p1 = getPointAt(i); final Point p2 = getPointAt(i + 1); final double sample1 = p1.getSample(); final double sample2 = p2.getSample(); final Color color1 = p1.getColor(); final Color color2 = p2.getColor(); if (sample >= sample1 && sample <= sample2) { if (discrete) { return color1; } else { return computeColor(sample, sample1, sample2, color1, color2); } } } return Color.BLACK; }