## geotools-gt2-users

 [Geotools-gt2-users] Polynomial Warping and JAI From: Richard Gould - 2007-03-01 23:04:10 ```Hi, Given a set of ground control points (GCPs) and a non-referenced TIFF image, I am trying to create a GeoTiff that can be rendered by GeoTools. I'm giving a set of source points (image pixels) and destination points (world coordinates) to the WarpTransform2D class, and using that to create the WarpPolynomial object to perform the JAI operation, but the Warp that is created contains a strange affine transform. Although it is more than likely that I just don't quite understand what is going on. The test I am running it against uses a 25x25 pixel image. The source points and destination points are the same (so the warp shouldn't do anything to the image - the affine should be identity?) I perform a test transformation in the code, just using the WarpTransform2D on the point (12, 12) which should return (12, 12) or something very close, but it actually returns (0, 12). The Warp's affine transform: [[0.0, 0.0, 0.0], [0.0, 1.0, 0.0]] I would think that that would be the identity? The image returned by JAI is the same shape, but it is blank. When I change each '0' to '1' in the source and destination points, the affine transform becomes: [[529.9999921023847, 4.0E-15, -23.0], [2.9802258E-8, 1.0, 3.0E-15]] In this case, the image is stretched very far to the right (several thousand pixels, I believe). It retains the same height. Obviously I am doing something wrong here. Does anyone have any ideas that may help? Or any alternative suggestions to referencing a TIFF using just ground control points? Here is my test source code: Point2D[] src = new Point2D[4]; Point2D[] dest = new Point2D[4]; src[0] = new Point(0,0); dest[0] = new DirectPosition2D(0, 0); src[1] = new Point(0, 24); dest[1] = new DirectPosition2D(0, 24); src[2] = new Point(24, 24); dest[2] = new DirectPosition2D(24, 24); src[3] = new Point(24, 0); dest[3] = new DirectPosition2D(24, 0); int deg = 1; WarpTransform2D wt = new WarpTransform2D(src, dest, deg); System.out.println("Test Transform: " + wt.transform(new java.awt.Point(12, 12), null)); InputStream is = getClass().getResourceAsStream("img.png"); BufferedImage sourceImage = ImageIO.read(is); Viewer.show(sourceImage); Warp warp = WarpTransform2D.getWarp("", wt); ParameterBlock paramBlk = new ParameterBlock().addSource(sourceImage); paramBlk = paramBlk.add(warp); JAI processor = JAI.getDefaultInstance(); String operation = "Warp"; RenderingHints targetHints = new RenderingHints(null); RenderedOp targetImage = processor.createNS(operation, paramBlk, targetHints); Viewer.show(targetImage); ```
 Re: [Geotools-gt2-users] Polynomial Warping and JAI From: Martin Desruisseaux - 2007-03-08 04:35:33 ```Richard Gould a écrit : > I'm giving a set of source points (image pixels) and destination points > (world coordinates) to the WarpTransform2D class, and using that to > create the WarpPolynomial object to perform the JAI operation, but the > Warp that is created contains a strange affine transform. Although it is > more than likely that I just don't quite understand what is going on. WarpTransform2D is build on top of javax.media.jai.WarpPolynomial.createWarp(...) I noticed strange behavior when the amount of points is close to the required minimum. It sound like that this method need slightly overdetermined set of points in order to give good result. > The Warp's affine transform: > [[0.0, 0.0, 0.0], [0.0, 1.0, 0.0]] > > I would think that that would be the identity? The image returned by JAI > is the same shape, but it is blank. A line with only 0.0 values is suspect and is probably responsible for the blank image... > Here is my test source code: > > src[0] = new Point(0,0); > dest[0] = new DirectPosition2D(0, 0); > > src[1] = new Point(0, 24); > dest[1] = new DirectPosition2D(0, 24); > > src[2] = new Point(24, 24); > dest[2] = new DirectPosition2D(24, 24); > > src[3] = new Point(24, 0); > dest[3] = new DirectPosition2D(24, 0); I'm really not sure, but it may be worth to try the following: * Provides some additional points * Avoid to provides only points that are on the same line or same columns (i.e. try to provides points that looks like more random). I really don't know if it will help; it is just a guess. In the referencing module test suite, we create affine transform and quadratic transform from a set of 100 random points, and it work. http://svn.geotools.org/geotools/trunk/gt/modules/library/referencing/src/test/java/org/geotools/referencing/operation/transform/WarpTransformTest.java 100 points is probably much more than needed; it should work with much less points, but I don't know what the "real" minimum is. It seems to be more than what is currently documented. Martin ```