RandomIterFactory.create(renderedImage, new Rectangle(0, 0, width, height));
iter = RandomIterFactory.create(inputRI, null);
public void loadData() throws KlabException { if (_loaded) return; /* * get rid of old image if we had one */ if (image != null) { image = null; } image = coverage.getRenderedImage(); itera = RandomIterFactory.create(image, null); _loaded = true; }
public void loadData() throws KlabException { checkCoverage(); /* * get rid of old image if we had one */ if (image != null) { image = null; } image = coverage.getRenderedImage(); itera = RandomIterFactory.create(image, null); _loaded = true; }
private void extendAsFloat(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); Rectangle samplingBounds = new Rectangle(0, 0, 2 * maxDistance + 1, 2 * maxDistance + 1); RandomIter srcIter = RandomIterFactory.create(sourceImage, bounds); float[] pixel = new float[raster.getNumBands()]; for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { samplingBounds.setLocation(x - maxDistance, y - maxDistance); Rectangle sourceSamplingBounds = samplingBounds.intersection(bounds); int sx = rand.nextInt(sourceSamplingBounds.width) + sourceSamplingBounds.x; int sy = rand.nextInt(sourceSamplingBounds.height) + sourceSamplingBounds.y; srcIter.getPixel(sx, sy, pixel); raster.setPixel(x, y, pixel); } } } }
private void extendAsDouble(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); Rectangle samplingBounds = new Rectangle(0, 0, 2 * maxDistance + 1, 2 * maxDistance + 1); RandomIter srcIter = RandomIterFactory.create(sourceImage, bounds); double[] pixel = new double[raster.getNumBands()]; for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { samplingBounds.setLocation(x - maxDistance, y - maxDistance); Rectangle sourceSamplingBounds = samplingBounds.intersection(bounds); int sx = rand.nextInt(sourceSamplingBounds.width) + sourceSamplingBounds.x; int sy = rand.nextInt(sourceSamplingBounds.height) + sourceSamplingBounds.y; srcIter.getPixel(sx, sy, pixel); raster.setPixel(x, y, pixel); } } } }
private void extendAsDouble(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); Rectangle samplingBounds = new Rectangle(0, 0, 2 * maxDistance + 1, 2 * maxDistance + 1); RandomIter srcIter = RandomIterFactory.create(sourceImage, bounds); double[] pixel = new double[raster.getNumBands()]; for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { samplingBounds.setLocation(x - maxDistance, y - maxDistance); Rectangle sourceSamplingBounds = samplingBounds.intersection(bounds); int sx = rand.nextInt(sourceSamplingBounds.width) + sourceSamplingBounds.x; int sy = rand.nextInt(sourceSamplingBounds.height) + sourceSamplingBounds.y; srcIter.getPixel(sx, sy, pixel); raster.setPixel(x, y, pixel); } } } }
private void extendAsInt(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); Rectangle samplingBounds = new Rectangle(0, 0, 2 * maxDistance + 1, 2 * maxDistance + 1); RandomIter srcIter = RandomIterFactory.create(sourceImage, bounds); int[] pixel = new int[raster.getNumBands()]; for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { samplingBounds.setLocation(x - maxDistance, y - maxDistance); Rectangle sourceSamplingBounds = samplingBounds.intersection(bounds); int sx = rand.nextInt(sourceSamplingBounds.width) + sourceSamplingBounds.x; int sy = rand.nextInt(sourceSamplingBounds.height) + sourceSamplingBounds.y; srcIter.getPixel(sx, sy, pixel); raster.setPixel(x, y, pixel); } } } }
private void extendAsFloat(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); Rectangle samplingBounds = new Rectangle(0, 0, 2 * maxDistance + 1, 2 * maxDistance + 1); RandomIter srcIter = RandomIterFactory.create(sourceImage, bounds); float[] pixel = new float[raster.getNumBands()]; for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { samplingBounds.setLocation(x - maxDistance, y - maxDistance); Rectangle sourceSamplingBounds = samplingBounds.intersection(bounds); int sx = rand.nextInt(sourceSamplingBounds.width) + sourceSamplingBounds.x; int sy = rand.nextInt(sourceSamplingBounds.height) + sourceSamplingBounds.y; srcIter.getPixel(sx, sy, pixel); raster.setPixel(x, y, pixel); } } } }
private void extendAsInt(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); Rectangle samplingBounds = new Rectangle(0, 0, 2 * maxDistance + 1, 2 * maxDistance + 1); RandomIter srcIter = RandomIterFactory.create(sourceImage, bounds); int[] pixel = new int[raster.getNumBands()]; for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { samplingBounds.setLocation(x - maxDistance, y - maxDistance); Rectangle sourceSamplingBounds = samplingBounds.intersection(bounds); int sx = rand.nextInt(sourceSamplingBounds.width) + sourceSamplingBounds.x; int sy = rand.nextInt(sourceSamplingBounds.height) + sourceSamplingBounds.y; srcIter.getPixel(sx, sy, pixel); raster.setPixel(x, y, pixel); } } } }
public Coverage2DState(GridCoverage2D coverage, IObservableSemantics observable, IScale scale, IObserver observer, IDirectObservation context) { // FIXME see what to do with dynamic state super(observable, scale, false, false, context); SpaceExtent ext = (SpaceExtent) scale.getSpace(); if (ext.getGrid() == null) { throw new KlabRuntimeException("cannot return a raster layer from a non-grid extent"); } _grid = ext.getGrid(); _image = coverage.getRenderedImage(); _itera = RandomIterFactory.create(_image, null); _coverage = coverage; }
private RoiAccessor buildRoiAccessor(ROI sourceROI) { if (sourceROI != null) { final PlanarImage roiImage = sourceROI.getAsImage(); final RandomIter roiIter = RandomIterFactory.create(roiImage, null); final int minRoiX = roiImage.getMinX(); final int minRoiY = roiImage.getMinY(); final int roiW = roiImage.getWidth(); final int roiH = roiImage.getHeight(); return new RoiAccessor(roiIter, sourceROI, roiImage, minRoiX, minRoiY, roiW, roiH); } return null; }
private void extendAsShort(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); Rectangle samplingBounds = new Rectangle(0, 0, 2 * maxDistance + 1, 2 * maxDistance + 1); RandomIter srcIter = RandomIterFactory.create(sourceImage, bounds); int[] pixel = new int[raster.getNumBands()]; for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { samplingBounds.setLocation(x - maxDistance, y - maxDistance); Rectangle sourceSamplingBounds = samplingBounds.intersection(bounds); int sx = rand.nextInt(sourceSamplingBounds.width) + sourceSamplingBounds.x; int sy = rand.nextInt(sourceSamplingBounds.height) + sourceSamplingBounds.y; srcIter.getPixel(sx, sy, pixel); for (int b = 0; b < raster.getNumBands(); b++) { raster.setSample(x, y, b, clamp(pixel[b], Short.MIN_VALUE, Short.MAX_VALUE)); } } } } }
private void extendAsShort(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); Rectangle samplingBounds = new Rectangle(0, 0, 2 * maxDistance + 1, 2 * maxDistance + 1); RandomIter srcIter = RandomIterFactory.create(sourceImage, bounds); int[] pixel = new int[raster.getNumBands()]; for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { samplingBounds.setLocation(x - maxDistance, y - maxDistance); Rectangle sourceSamplingBounds = samplingBounds.intersection(bounds); int sx = rand.nextInt(sourceSamplingBounds.width) + sourceSamplingBounds.x; int sy = rand.nextInt(sourceSamplingBounds.height) + sourceSamplingBounds.y; srcIter.getPixel(sx, sy, pixel); for (int b = 0; b < raster.getNumBands(); b++) { raster.setSample(x, y, b, clamp(pixel[b], Short.MIN_VALUE, Short.MAX_VALUE)); } } } } }
public void setImage(RenderedImage image) { this.image = image; if(image == null) { display.setVisible(false); pixelIter = null; } else { display.setImage(image); display.setVisible(true); pixelIter = RandomIterFactory.create(image, null); ipixel = new int[image.getSampleModel().getNumBands()]; dpixel = new double[image.getSampleModel().getNumBands()]; } }
public static int countNodata(GridCoverage2D layer, IDirectObservation context) throws KlabException { SpaceExtent ext = (SpaceExtent) context.getScale().getSpace(); if (ext.getGrid() == null) { throw new KlabValidationException("cannot return a raster layer from a non-grid extent"); } Grid grid = ext.getGrid(); RenderedImage image = layer.getRenderedImage(); RandomIter itera = RandomIterFactory.create(image, null); int nodata = 0; for (int i = 0; i < grid.getCellCount(); i++) { int[] xy = grid.getXYOffsets(i); double d = itera.getSampleDouble(xy[0], xy[1], 0); if (Double.isNaN(d)) { nodata ++; } } return nodata; }
public void setImage(RenderedImage image) { this.image = image; if(image == null) { display.setVisible(false); pixelIter = null; } else { display.setImage(image); display.setVisible(true); pixelIter = RandomIterFactory.create(image, null); ipixel = new int[image.getSampleModel().getNumBands()]; dpixel = new double[image.getSampleModel().getNumBands()]; } }
private void assertCopy(RenderedImage src, RenderedOp op, int dataType) { // check it's a copy with the expected values assertEquals(src.getMinX(), op.getMinX()); assertEquals(src.getWidth(), op.getWidth()); assertEquals(src.getMinY(), op.getMinY()); assertEquals(src.getHeight(), op.getHeight()); assertEquals(dataType, op.getSampleModel().getDataType()); RandomIter srcIter = RandomIterFactory.create(src, null); RandomIter opIter = RandomIterFactory.create(op, null); for(int y = src.getMinY(); y < src.getMinY() + src.getHeight(); y++) { for(int x = src.getMinX(); x < src.getMinX() + src.getWidth(); x++) { double expected = srcIter.getSampleDouble(x, y, 0); double actual = opIter.getSampleDouble(x, y, 0); assertEquals(expected, actual, 0d); } } }
@Test public void builderCreatesDestImage() throws Exception { System.out.println(" builder creating dest image"); String script = "init { n = 0; } dest = n++ ;" ; jb.dest("dest", IMG_WIDTH, IMG_WIDTH).script(script).getRuntime().evaluateAll(null); RenderedImage img = jb.getImage("dest"); assertNotNull(img); RandomIter iter = RandomIterFactory.create(img, null); int k = 0; for (int y = 0; y < IMG_WIDTH; y++) { for (int x = 0; x < IMG_WIDTH; x++) { assertEquals(k, iter.getSample(x, y, 0)); k++ ; } } }