/** * Returns a Region representing the intersection of this Region with the * given Region. If the two Regions do not intersect, the result is an * empty Region. */ public Region intersection(Region r) { int x = Math.max(this.x, r.x); int y = Math.max(this.y, r.y); int w = Math.min(this.x + this.width, r.x + r.width) - x; int h = Math.min(this.y + this.height, r.y + r.height) - y; if (w < 0) w = 0; if (h < 0) h = 0; return new Region(x, y, w, h); }
/** * Returns a Region representing the intersection of this Region with the * given Region. If the two Regions do not intersect, the result is an * empty Region. * * @param r the region for which to calculate an intersection (or overlap) * @return a Region representing the intersection (overlap) of the two Regions. * If the two Regions have no common area, then the width and/or height * of the returned Region will be 0. null is never returned. */ public Region intersection(Region r) { int x = Math.max(this.x, r.x); int y = Math.max(this.y, r.y); int w = Math.min(this.x + this.width, r.x + r.width) - x; int h = Math.min(this.y + this.height, r.y + r.height) - y; if (w < 0) w = 0; if (h < 0) h = 0; return new Region(x, y, w, h); }
/** * Returns true if the point specified by the given X and Y coordinates * is contained within this region. * * @param xc the integer X coordinate of a point * @param yc the integer Y coordinate of a point * @return true if this Region encloses the given point */ public boolean containsPoint(int xc, int yc) { return intersects(new Region(xc, yc, 1, 1)); }
/** * Returns true if the point specified by the given X and Y coordinates * is contained within this region. */ public boolean containsPoint(int xc, int yc) { return intersects(new Region(xc, yc, 1, 1)); }
public byte[] get(int x, int y, int w, int h) throws CodecException, IOException { Region[] keys = compressedTiles.keySet().toArray(new Region[0]); Region r = new Region(x, y, w, h); for (Region key : keys) { if (key.intersects(r)) { r = key; } } if (!r.equals(lastRegion)) { lastRegion = r; byte[] compressed = null; compressed = compressedTiles.get(r); if (compressed == null) return null; lastTile = codec.decompress(compressed, options); } int pixel = options.channels * (options.bitsPerSample / 8); byte[] buf = new byte[w * h * pixel]; for (int i=0; i<h; i++) { System.arraycopy(lastTile, r.width * pixel * (i + y - r.y) + (x - r.x), buf, i * w * pixel, pixel * w); } return buf; } }
public void add(byte[] pixels, int x, int y, int w, int h) throws CodecException, IOException { toCompress.add(pixels); row++; if ((y % ROW_COUNT) == ROW_COUNT - 1 || y == getHeight() - 1 || y == yy + hh - 1) { Region r = new Region(x, y - row + 1, w, row); options.width = w; options.height = row; options.channels = 1; options.bitsPerSample = 8; options.signed = false; byte[] compressed = codec.compress(toCompress.toByteArray(), options); compressedTiles.put(r, compressed); toCompress.clear(); } }
public void add(int[] pixels, int x, int y, int w, int h) throws CodecException, IOException { byte[] buf = new byte[pixels.length * 3]; for (int i=0; i<pixels.length; i++) { buf[i * 3] = (byte) ((pixels[i] & 0xff0000) >> 16); buf[i * 3 + 1] = (byte) ((pixels[i] & 0xff00) >> 8); buf[i * 3 + 2] = (byte) (pixels[i] & 0xff); } toCompress.add(buf); row++; if ((y % ROW_COUNT) == ROW_COUNT - 1 || y == getHeight() - 1 || y == yy + hh - 1) { Region r = new Region(x, y - row + 1, w, row); options.width = w; options.height = row; options.channels = 3; options.bitsPerSample = 8; options.signed = false; byte[] compressed = codec.compress(toCompress.toByteArray(), options); compressedTiles.put(r, compressed); toCompress.clear(); row = 0; } }
/** Valid only after {@link ImportStep#STACK}. */ public Region getCropRegion(int s) { assertStep(ImportStep.STACK); Region region = options.doCrop() ? options.getCropRegion(s) : null; reader.setSeries(s); int sizeX = reader.getSizeX(), sizeY = reader.getSizeY(); if (region == null) { // entire image plane is the default region region = new Region(0, 0, sizeX, sizeY); } else { // bounds checking for cropped region if (region.x < 0) region.x = 0; if (region.y < 0) region.y = 0; if (region.width <= 0 || region.x + region.width > sizeX) { region.width = sizeX - region.x; } if (region.height <= 0 || region.y + region.height > sizeY) { region.height = sizeX - region.y; } } return region; }
/** Valid only after {@link ImportStep#STACK}. */ public Region getCropRegion(int s) { assertStep(ImportStep.STACK); Region region = options.doCrop() ? options.getCropRegion(s) : null; reader.setSeries(s); int sizeX = reader.getSizeX(), sizeY = reader.getSizeY(); if (region == null) { // entire image plane is the default region region = new Region(0, 0, sizeX, sizeY); } else { // bounds checking for cropped region if (region.x < 0) region.x = 0; if (region.y < 0) region.y = 0; if (region.width <= 0 || region.x + region.width > sizeX) { region.width = sizeX - region.x; } if (region.height <= 0 || region.y + region.height > sizeY) { region.height = sizeX - region.y; } } return region; }
public void openSubImage(String title, Double no, Double x, Double y, Double w, Double h) throws FormatException, IOException { ImporterOptions options = new ImporterOptions(); options.setWindowless(true); options.setId(r.getCurrentFile()); options.setCrop(true); options.setSpecifyRanges(true); options.setSeriesOn(r.getSeries(), true); int[] zct = r.getZCTCoords(no.intValue()); options.setCBegin(r.getSeries(), zct[1]); options.setZBegin(r.getSeries(), zct[0]); options.setTBegin(r.getSeries(), zct[2]); options.setCEnd(r.getSeries(), zct[1]); options.setZEnd(r.getSeries(), zct[0]); options.setTEnd(r.getSeries(), zct[2]); Region region = new Region(x.intValue(), y.intValue(), w.intValue(), h.intValue()); options.setCropRegion(r.getSeries(), region); ImportProcess process = new ImportProcess(options); process.execute(); ImagePlusReader reader = new ImagePlusReader(process); final ImagePlus imp = reader.openImagePlus()[0]; Calibrator calibrator = new Calibrator(process); calibrator.applyCalibration(imp); process.getReader().close(); imp.show(); }
public void openSubImage(String title, Double no, Double x, Double y, Double w, Double h) throws FormatException, IOException { ImporterOptions options = new ImporterOptions(); options.setWindowless(true); options.setId(r.getCurrentFile()); options.setCrop(true); options.setSpecifyRanges(true); options.setSeriesOn(r.getSeries(), true); int[] zct = r.getZCTCoords(no.intValue()); options.setCBegin(r.getSeries(), zct[1]); options.setZBegin(r.getSeries(), zct[0]); options.setTBegin(r.getSeries(), zct[2]); options.setCEnd(r.getSeries(), zct[1]); options.setZEnd(r.getSeries(), zct[0]); options.setTEnd(r.getSeries(), zct[2]); Region region = new Region(x.intValue(), y.intValue(), w.intValue(), h.intValue()); options.setCropRegion(r.getSeries(), region); ImportProcess process = new ImportProcess(options); process.execute(); ImagePlusReader reader = new ImagePlusReader(process); final ImagePlus imp = reader.openImagePlus()[0]; Calibrator calibrator = new Calibrator(process); calibrator.applyCalibration(imp); process.getReader().close(); imp.show(); }
/** tests BF's options.setCrop() and options.setCropRegion() */ private void memoryCropTester(int x, int y, int ox, int oy, int cropSize) { verifyCropInput(x, y, ox, oy, cropSize); // needed for this test String path = constructFakeFilename("crop", FormatTools.UINT8, x, y, 1, 1, 1, -1, false, -1, false, -1); // open image ImagePlus[] imps = null; try { ImporterOptions options = new ImporterOptions(); options.setAutoscale(false); options.setId(path); options.setCrop(true); options.setCropRegion(0, new Region(ox, oy, cropSize, cropSize)); imps = BF.openImagePlus(options); } catch (IOException e) { fail(e.getMessage()); } catch (FormatException e) { fail(e.getMessage()); } // test results impsCountTest(imps,1); ImagePlus imp = imps[0]; xyzctTest(imp,cropSize,cropSize,1,1,1); // test we got the right pixels croppedPixelsTest(imp,ox,cropSize); }
options.setInputOrder(0, bfChanOrd(swappedOrder)); options.setCrop(true); options.setCropRegion(0, new Region(cropOriginX,cropOriginY,cropSizeX,cropSizeY)); options.setTStep(0, stepBy); options.setTBegin(0, start);
@Override protected boolean harvestResults(GenericDialog gd) { final int seriesCount = process.getSeriesCount(); final IFormatReader r = process.getReader(); for (int s=0; s<seriesCount; s++) { if (!options.isSeriesOn(s)) continue; r.setSeries(s); Region region = new Region(); region.x = (int) gd.getNextNumber(); region.y = (int) gd.getNextNumber(); region.width = (int) gd.getNextNumber(); region.height = (int) gd.getNextNumber(); if (region.x < 0) region.x = 0; if (region.y < 0) region.y = 0; if (region.x >= r.getSizeX()) region.x = r.getSizeX() - region.width - 1; if (region.y >= r.getSizeY()) region.y = r.getSizeY() - region.height - 1; if (region.width < 1) region.width = 1; if (region.height < 1) region.height = 1; if (region.width + region.x > r.getSizeX()) { region.width = r.getSizeX() - region.x; } if (region.height + region.y > r.getSizeY()) { region.height = r.getSizeY() - region.y; } options.setCropRegion(s, region); } return true; }
@Override protected boolean harvestResults(GenericDialog gd) { final int seriesCount = process.getSeriesCount(); final IFormatReader r = process.getReader(); for (int s=0; s<seriesCount; s++) { if (!options.isSeriesOn(s)) continue; r.setSeries(s); Region region = new Region(); region.x = (int) gd.getNextNumber(); region.y = (int) gd.getNextNumber(); region.width = (int) gd.getNextNumber(); region.height = (int) gd.getNextNumber(); if (region.x < 0) region.x = 0; if (region.y < 0) region.y = 0; if (region.x >= r.getSizeX()) region.x = r.getSizeX() - region.width - 1; if (region.y >= r.getSizeY()) region.y = r.getSizeY() - region.height - 1; if (region.width < 1) region.width = 1; if (region.height < 1) region.height = 1; if (region.width + region.x > r.getSizeX()) { region.width = r.getSizeX() - region.x; } if (region.height + region.y > r.getSizeY()) { region.height = r.getSizeY() - region.y; } options.setCropRegion(s, region); } return true; }
int plane = no / getSizeC(); int c = no % getSizeC(); Region region = new Region(x, y, w, h);
int plane = no / getSizeC(); int c = no % getSizeC(); Region region = new Region(x, y, w, h);