@Test public void testTranslatedImageTileGridROINoData() { // Testing color indexing with Nodata and ROI BufferedImage image_ = new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY); Graphics g = image_.createGraphics(); g.setColor(Color.WHITE); g.fillRect(236, 236, 20, 20); g.setColor(new Color(80, 80, 80)); // A dark gray g.fillRect(216, 216, 20, 20); g.setColor(new Color(200, 200, 200)); // A light gray g.fillRect(216, 236, 20, 20); g.dispose(); TiledImage image = new TiledImage( 0, 0, 256, 256, 128, 128, image_.getColorModel().createCompatibleSampleModel(256, 256), image_.getColorModel()); image.set(image_); Range range = RangeFactory.create((byte) 255, (byte) 255); ROIShape roi = new ROIShape(new Rectangle(0, 0, 20, 20)); RenderedImage indexed = quantize(image, roi, range, 1); assertTrue(indexed.getColorModel() instanceof IndexColorModel); IndexColorModel icm = (IndexColorModel) indexed.getColorModel(); assertEquals(4, icm.getMapSize()); // Black background, white fill, // light gray fill, dark gray fill = // 4 colors // check image not black RenderedImage component = forceComponentColorModel(indexed); final double[][] coeff = new double[1][5]; Arrays.fill(coeff[0], 0, 4, 1.0 / 4); component = BandCombineDescriptor.create(component, coeff, null, null, destinationNoData, null); StatsType[] stats = new StatsType[] {StatsType.EXTREMA}; component = StatisticsDescriptor.create(component, 1, 1, null, null, false, new int[] {0}, stats, null); Statistics stat = ((Statistics[][]) component.getProperty(Statistics.STATS_PROPERTY))[0][0]; double[] result = (double[]) stat.getResult(); final double minimum = result[0]; final double maximum = result[1]; assertFalse(Math.abs(maximum - minimum) < TOLERANCE); }
@Test public void testTranslatedImageTileGrid() { BufferedImage image_ = new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY); Graphics g = image_.createGraphics(); g.setColor(Color.WHITE); g.fillRect(236, 236, 20, 20); g.setColor(new Color(80, 80, 80)); // A dark gray g.fillRect(216, 216, 20, 20); g.setColor(new Color(200, 200, 200)); // A light gray g.fillRect(216, 236, 20, 20); g.dispose(); TiledImage image = new TiledImage( 0, 0, 256, 256, 128, 128, image_.getColorModel().createCompatibleSampleModel(256, 256), image_.getColorModel()); image.set(image_); CustomPaletteBuilder builder = new CustomPaletteBuilder(image, 256, 1, 1, 1); RenderedImage indexed = builder.buildPalette().getIndexedImage(); assertTrue(indexed.getColorModel() instanceof IndexColorModel); IndexColorModel icm = (IndexColorModel) indexed.getColorModel(); assertEquals( 4, icm .getMapSize()); // Black background, white fill, light gray fill, dark gray fill = 4 // colors // check image not black ImageWorker iw = new ImageWorker(indexed).forceComponentColorModel().intensity(); double[] mins = iw.getMinimums(); double[] maxs = iw.getMaximums(); boolean result = true; for (int i = 0; i < mins.length; i++) { result = mins[i] == maxs[i] ? false : result; } assertTrue(result); }
/** * Creates a SampleOpImage with the given ParameterBlock if the SampleOpImage can handle the * particular ParameterBlock. */ @Override public RenderedImage create(ParameterBlock paramBlock, RenderingHints renderHints) { PlanarImage source1 = (PlanarImage) paramBlock.getRenderedSource(0); if (source1 == null) { return null; } ROIShape shape = (ROIShape) paramBlock.getObjectParameter(0); if (shape == null) { return source1; } TiledImage image; if (ImageUtil.isBinary(source1.getSampleModel())) { image = new TiledImage( source1.getMinX(), source1.getMinY(), source1.getWidth(), source1.getHeight(), source1.getTileGridXOffset(), source1.getTileGridYOffset(), LayoutUtil.createBinarySampelModel(), LayoutUtil.createBinaryIndexColorModel()); } else { // rgb cannot be null or have less than one value Byte[] rgb = (Byte[]) paramBlock.getObjectParameter(1); int nbands = source1.getSampleModel().getNumBands(); if (rgb.length != nbands) { Byte fillVal = rgb[0]; rgb = new Byte[nbands]; Arrays.fill(rgb, fillVal); } image = ImageFiler.getEmptyTiledImage(rgb, source1.getWidth(), source1.getHeight()); } image.set(source1, shape); return image; }