001/******************************************************************************* 002 * This software is provided as a supplement to the authors' textbooks on digital 003 * image processing published by Springer-Verlag in various languages and editions. 004 * Permission to use and distribute this software is granted under the BSD 2-Clause 005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 006 * Copyright (c) 2006-2016 Wilhelm Burger, Mark J. Burge. All rights reserved. 007 * Visit http://imagingbook.com for additional details. 008 *******************************************************************************/ 009package imagingbook.pub.lucaskanade; 010 011import ij.gui.Roi; 012import ij.gui.ShapeRoi; 013import ij.process.FloatProcessor; 014import ij.process.ImageProcessor; 015import imagingbook.pub.geometry.mappings.linear.LinearMapping; 016 017import java.awt.Color; 018import java.awt.Rectangle; 019import java.awt.geom.Path2D; 020import java.awt.geom.Point2D; 021import java.util.LinkedList; 022import java.util.List; 023 024@Deprecated 025public class RoiUtils { 026 027 @Deprecated 028 public static List<Point2D> getWarpedPointsCentered(Roi roi, LinearMapping W) { 029 Rectangle bounds = roi.getBounds(); 030 List<Point2D> oPts = new LinkedList<Point2D>(); 031 float xC = bounds.width/2; 032 float yC = bounds.height/2; 033 oPts.add(new Point2D.Float(0 - xC, 0 - yC)); 034 oPts.add(new Point2D.Float(bounds.width - xC, 0 - yC)); 035 oPts.add(new Point2D.Float(bounds.width - xC, bounds.height - yC)); 036 oPts.add(new Point2D.Float(0 - xC, bounds.height - yC)); 037 List<Point2D> wPts = new LinkedList<Point2D>(); 038 for (Point2D op : oPts) { 039 wPts.add(W.applyTo(op)); 040 //pts.add(ipm); 041 } 042 return wPts; 043 } 044 045 @Deprecated 046 public static Roi makePolygon(Point2D[] points, double strokeWidth, Color color) { 047 Path2D poly = new Path2D.Double(); 048 if (points.length > 0) { 049 poly.moveTo(points[0].getX(), points[0].getY()); 050 for (int i = 1; i < points.length; i++) { 051 poly.lineTo(points[i].getX(), points[i].getY()); 052 } 053 poly.closePath(); 054 } 055 Roi shapeRoi = new ShapeRoi(poly); 056 shapeRoi.setStrokeWidth(strokeWidth); 057 shapeRoi.setStrokeColor(color); 058 return shapeRoi; 059 } 060 061 062// @Deprecated 063// public static void listPolygon(List<Point2D> points, String title) { 064// IJ.log("Polygon " + title + ":"); 065// int i = 0; 066// for (Point2D p : points) { 067// i++; 068// IJ.log(" v" + i + "= " + p.toString()); 069// } 070// } 071 072 // --------------------------------------------------------------------------- 073 074 @Deprecated 075 public static FloatProcessor getUnwarpedImage(ImageProcessor I, LinearMapping W, int w, int h) { 076 FloatProcessor J = new FloatProcessor(w, h); 077 int uc = w/2; // center (origin) of R 078 int vc = h/2; 079 for (int u = 0; u < w; u++) { 080 for (int v = 0; v < h; v++) { 081 double[] x = {u - uc, v - vc}; // position w.r.t. the center of R 082 double[] xw = W.applyTo(x); // warp from x -> xw 083 float val = (float) I.getInterpolatedValue(xw[0], xw[1]); 084 J.setf(u, v, val); 085 } 086 } 087 return J; 088 } 089 090}