/** * Gets the transform which converts from {@code worldBounds} to {@code imageBounds}. * This method is a shortcut for {@code getTransform(worldBounds, imageBounds, false, false)}. * * @param worldBounds the coordinate bounds in world (user-defined) units * @param imageBounds the image bounds * * @return a new transform instance * * @throws IllegalArgumentException if either argument is {@code null} or empty */ public static CoordinateTransform getTransform(Rectangle2D worldBounds, Rectangle imageBounds) { return getTransform(worldBounds, imageBounds, false, false); }
/** * Gets the transform which converts from {@code worldBounds} to {@code imageBounds}. * This method is a shortcut for {@code getTransform(worldBounds, imageBounds, false, false)}. * * @param worldBounds the coordinate bounds in world (user-defined) units * @param imageBounds the image bounds * * @return a new transform instance * * @throws IllegalArgumentException if either argument is {@code null} or empty */ public static CoordinateTransform getTransform(Rectangle2D worldBounds, Rectangle imageBounds) { return getTransform(worldBounds, imageBounds, false, false); }
/** * Creates a transform for working in the unit rectangle, ie. proportional * image coordinates where both X and Y ordinates vary from 0 to 1. * * @param imageBounds the image bounds * * @return a new transform instance * * @throws IllegalArgumentException if {@code imageBounds} is {@code null} or empty */ public static CoordinateTransform unitBounds(Rectangle imageBounds) { if (imageBounds == null || imageBounds.isEmpty()) { throw new IllegalArgumentException("imageBounds must not be null or empty"); } return getTransform(new Rectangle(0, 0, 1, 1), imageBounds); }
/** * Creates a transform for working in the unit rectangle, ie. proportional * image coordinates where both X and Y ordinates vary from 0 to 1. * * @param imageBounds the image bounds * * @return a new transform instance * * @throws IllegalArgumentException if {@code imageBounds} is {@code null} or empty */ public static CoordinateTransform unitBounds(Rectangle imageBounds) { if (imageBounds == null || imageBounds.isEmpty()) { throw new IllegalArgumentException("imageBounds must not be null or empty"); } return getTransform(new Rectangle(0, 0, 1, 1), imageBounds); }
public void runtimeExample() throws Exception { // docs start // World bounds Rectangle2D worldBounds = new Rectangle2D.Double( 750000, 6500000, 100000, 50000); // Common image bounds Rectangle imageBounds = new Rectangle(0, 0, 4000, 2000); // Set the bounds (world units) and resolution of the // processing area runtimeObj.setWorldByNumPixels(worldBounds, 4000, 2000); // Create a new transform that converts from world units to // pixel positions using the CoordinateTransforms helper class CoordinateTransform tr = CoordinateTransforms.getTransform( worldBounds, imageBounds); // Set this coordinate transform object to be used with all images runtimeObj.setDefaultTransform(tr); // docs end } }
@Test public void getTransformReverseYDir() throws Exception { System.out.println(" getTransform with reversed Y axis"); Rectangle world = new Rectangle(5000, 4000, 10000, 10000); Rectangle image = new Rectangle(10, -10, 100, 100); CoordinateTransform tr = CoordinateTransforms.getTransform(world, image, false, true); assertPoint(image.x, image.y, tr.worldToImage(world.x, world.y + world.height, null)); assertPoint(image.x + image.width, image.y + image.height, tr.worldToImage(world.x + world.width, world.y, null)); }
@Test public void getTransformReverseXDir() throws Exception { System.out.println(" getTransform with reversed X axis"); Rectangle world = new Rectangle(5000, 4000, 10000, 10000); Rectangle image = new Rectangle(10, -10, 100, 100); CoordinateTransform tr = CoordinateTransforms.getTransform(world, image, true, false); assertPoint(image.x, image.y, tr.worldToImage(world.x + world.width, world.y, null)); assertPoint(image.x + image.width, image.y + image.height, tr.worldToImage(world.x, world.y + world.height, null)); }
@Test public void getTransformDefault() throws Exception { System.out.println(" getTransform method"); Rectangle world = new Rectangle(0, 0, 10000, 10000); Rectangle image = new Rectangle(10, -10, 100, 100); CoordinateTransform tr = CoordinateTransforms.getTransform(world, image); assertPoint(image.x, image.y, tr.worldToImage(world.x, world.y, null)); assertPoint(image.x + image.width, image.y + image.height, tr.worldToImage(world.x + world.width, world.y + world.height, null)); }
CoordinateTransform tr = CoordinateTransforms.getTransform(worldBounds, imageBounds);
runtime.setWorldByResolution(worldBounds, RES, RES); CoordinateTransform tr = CoordinateTransforms.getTransform(worldBounds, imageBounds); runtime.setDestinationImage("dest", destImg, tr); runtime.evaluateAll(null);
CoordinateTransform srcTr = CoordinateTransforms.getTransform(worldBounds, srcBounds); runtime.setSourceImage("src", srcImg, srcTr); runtime.setDestinationImage("dest", destImg);
CoordinateTransform tr = CoordinateTransforms.getTransform(worldBounds, imageBounds);