LineExtractor.java
package ac.essex.ooechs.imaging.commons.subpixel;
import ac.essex.ooechs.imaging.commons.Pixel;
import ac.essex.ooechs.imaging.commons.PixelLoader;
import java.awt.image.BufferedImage;
import java.awt.*;
/**
* Exracts linear parts out from an image. Simply specify the start point and
* end point of the line, and the width. Uses subpixel sampling so the new image
* is nice and clear.
*
* @author Olly Oechsle, University of Essex, Date: 14-Mar-2008
* @version 1.0
*/
public class LineExtractor {
public static PixelLoader extract(PixelLoader image, int width, Pixel start, Pixel end) {
return extract(image, width, start.x, start.y, end.x, end.y);
}
public static PixelLoader extract(PixelLoader image, int width, int startX, int startY, int endX, int endY) {
double dx = startX - endX;
double dy = startY - endY;
// find the mid point
double mx = startX - (dx / 2);
double my = startY - (dy / 2);
// want to see 10 pixels on either side of the line
int height = (int) Math.sqrt((dx * dx) + (dy * dy));
double angle = -Math.atan(dx/dy);
return SubPixel.extractRectangle(image, mx, my, width, height, angle);
}
}