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()); } }
private void setImageInfoCopy(ImageInfo imageInfo) { this.imageInfo = imageInfo.createDeepCopy(); }
/** * Transfers the colour palette into this image info. * * @param colorPaletteDef another colour palette * @param minSample the minium allowed sample value in the new colour palette * @param maxSample the maximum allowed sample value in the new colour palette * @param autoDistribute if true, points are distributed between minSample/maxSample. */ public void setColorPaletteDef(ColorPaletteDef colorPaletteDef, double minSample, double maxSample, boolean autoDistribute) { transferPoints(colorPaletteDef, minSample, maxSample, autoDistribute, getColorPaletteDef()); }
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; }
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; }
public DefaultImageInfoEditorModel(ImageInfo imageInfo) { super(imageInfo); Assert.argument(imageInfo.getColorPaletteDef() != null, "imageInfo"); }
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)), })); } }
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 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); } }
Assert.notNull(raster, "raster"); Assert.notNull(imageInfo, "imageInfo"); Assert.argument(imageInfo.getColorPaletteDef() != null, "imageInfo.getColorPaletteDef() != null"); Assert.notNull(pm, "pm"); final int height = raster.getSceneRasterHeight(); final int numPixels = width * height; 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); palette = raster.getImageInfo().getColors(); if (noDataIndex > 0) { palette = Arrays.copyOf(palette, palette.length + 1); convertPaletteToRgbSamples(palette, imageInfo.getNoDataColor(), numColorComponents, rgbSamples, indexValidator); pm.worked(40); image = applyHistogramMatching(image, imageInfo.getHistogramMatching()); pm.worked(10); checkCanceled(pm);
if (colorPaletteDef != null) { if (band.getIndexCoding() != null) { band.getImageInfo().setColors(colorPaletteDef.getColors()); } else { Stx stx = band.getStx(); band.getImageInfo().setColorPaletteDef(colorPaletteDef, stx.getMinimum(), stx.getMaximum(), false); band.getImageInfo().setNoDataColor(_noDataColor); if (imageInfo.getNoDataColor().getAlpha() < 255 && "BMP".equalsIgnoreCase(_formatName)) { if (_noDataColor != null) { imageInfo.setNoDataColor(_noDataColor); } else { imageInfo.setNoDataColor(Color.BLACK); imageInfo.setHistogramMatching(ImageInfo.getHistogramMatching(_histogramMatching)); image = ProductUtils.createRgbImage(bands, imageInfo, ProgressMonitor.NULL); if (image.getColorModel().hasAlpha() && "BMP".equalsIgnoreCase(_formatName)) {
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; }
final ColorPaletteDef paletteDefinition = band.getImageInfo().getColorPaletteDef(); sXmlW.printLine(indent + 2, DimapProductConstants.TAG_NUM_COLORS, paletteDefinition.getNumColors()); final Iterator iterator = paletteDefinition.getIterator(); band.getImageInfo().getNoDataColor(), sXmlW); sXmlW.printLine(indent + 2, DimapProductConstants.TAG_HISTOGRAM_MATCHING, band.getImageInfo().getHistogramMatching().toString());
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); }
ImageInfo imageInfo) { Color[] palette; ColorPaletteDef colorPaletteDef = imageInfo.getColorPaletteDef(); if (isClassificationBand(rasterDataNode)) { Color[] origPalette = colorPaletteDef.getColors(); palette = Arrays.copyOf(origPalette, origPalette.length + 1); palette[palette.length - 1] = imageInfo.getNoDataColor(); } else { palette = createColorPalette(imageInfo); final Color noDataColor = imageInfo.getNoDataColor(); final Byte[] noDataRGB = new Byte[]{ (byte) noDataColor.getRed(),
Assert.argument(rasters.length == 3, "rasters.length == 3"); Assert.notNull(imageInfo, "imageInfo"); Assert.argument(imageInfo.getRgbChannelDef() != null, "imageInfo.getRgbChannelDef() != null"); Assert.notNull(pm, "pm"); Color noDataColor = imageInfo.getNoDataColor(); final int numColorComponents = imageInfo.getColorComponentCount(); final int numPixels = width * height; final byte[] rgbSamples = new byte[numColorComponents * numPixels]; final RasterDataNode raster = rasters[i]; pm.setSubTaskName(taskMessages[i]); raster.quantizeRasterData(imageInfo.getRgbChannelDef().getMinDisplaySample(i), imageInfo.getRgbChannelDef().getMaxDisplaySample(i), imageInfo.getRgbChannelDef().getGamma(i), rgbSamples, numColorComponents - 1 - i, image = applyHistogramMatching(image, imageInfo.getHistogramMatching()); pm.worked(5); checkCanceled(pm);
currentChannelSources[channel] = newChannelSource; final ImageInfo imageInfo = parentForm.getImageInfo(); imageInfo.getRgbChannelDef().setSourceName(channel, channelSourceName); final ImageInfo info = newChannelSource.getImageInfo(com.bc.ceres.core.ProgressMonitor.NULL); final ColorPaletteDef def = info.getColorPaletteDef(); if (def != null) { imageInfo.getRgbChannelDef().setMinDisplaySample(channel, def.getMinDisplaySample()); imageInfo.getRgbChannelDef().setMaxDisplaySample(channel, def.getMaxDisplaySample());
@Override public void actionPerformed(ActionEvent e) { final boolean shouldLog10Display = logDisplayButton.isSelected(); final ImageInfo imageInfo = parentForm.getImageInfo(); if (shouldLog10Display) { final ColorPaletteDef cpd = imageInfo.getColorPaletteDef(); if (LogDisplay.checkApplicability(cpd)) { colorPaletteChooser.setLog10Display(shouldLog10Display); imageInfo.setLogScaled(shouldLog10Display); parentForm.applyChanges(); } else { LogDisplay.showNotApplicableInfo(parentForm.getContentPanel()); logDisplayButton.setSelected(false); } } else { colorPaletteChooser.setLog10Display(shouldLog10Display); imageInfo.setLogScaled(shouldLog10Display); parentForm.applyChanges(); } } });
/** * Creates a greyscale image from the given <code>{@link RasterDataNode}</code>. * <p/> * <p>The method uses the given raster data node's image information (an instance of <code>{@link * ImageInfo}</code>) to create the image. * * @param rasterDataNode the raster data node, must not be <code>null</code> * @param pm a monitor to inform the user about progress * * @return the color indexed image * * @throws IOException if the given raster data is not loaded and reload causes an I/O error * @see org.esa.beam.framework.datamodel.RasterDataNode#getImageInfo() */ public static BufferedImage createColorIndexedImage(final RasterDataNode rasterDataNode, ProgressMonitor pm) throws IOException { Guardian.assertNotNull("rasterDataNode", rasterDataNode); final int width = rasterDataNode.getSceneRasterWidth(); final int height = rasterDataNode.getSceneRasterHeight(); final ImageInfo imageInfo = rasterDataNode.getImageInfo(ProgressMonitor.NULL); final double newMin = imageInfo.getColorPaletteDef().getMinDisplaySample(); final double newMax = imageInfo.getColorPaletteDef().getMaxDisplaySample(); final byte[] colorIndexes = rasterDataNode.quantizeRasterData(newMin, newMax, 1.0, pm); final IndexColorModel cm = imageInfo.createIndexColorModel(rasterDataNode); final SampleModel sm = cm.createCompatibleSampleModel(width, height); final DataBuffer db = new DataBufferByte(colorIndexes, colorIndexes.length); final WritableRaster wr = WritableRaster.createWritableRaster(sm, db, null); return new BufferedImage(cm, wr, false, null); }
final int height = product.getSceneRasterHeight(); ImageInfo blueToRedGrad = new ImageInfo(new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(-1.0, Color.BLUE), new ColorPaletteDef.Point(0.0, Color.WHITE), new ColorPaletteDef.Point(1.0, Color.RED), })); ImageInfo amplGrad = new ImageInfo(new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(0.0, Color.WHITE), new ColorPaletteDef.Point(1.0, Color.RED), })); ImageInfo phaseGrad = new ImageInfo(new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(-Math.PI, Color.WHITE), new ColorPaletteDef.Point(0.0, Color.BLUE), configureBand(bandX, blueToRedGrad.clone(), "pixels", "Geo-coding X-displacement"); configureBand(bandY, blueToRedGrad.clone(), "pixels", "Geo-coding Y-displacement"); configureBand(bandAmpl, amplGrad.clone(), "pixels", "Geo-coding displacement amplitude"); configureBand(bandPhase, phaseGrad.clone(), "radians", "Geo-coding displacement phase");