HoughPreview.java
package ac.essex.ooechs.imaging.commons.edge.hough;
import ac.essex.ooechs.imaging.commons.util.panels.ImageFrame;
import ac.essex.ooechs.imaging.commons.fast.FastStatistics;
import ac.essex.ooechs.imaging.commons.PixelLoader;
import ac.essex.ooechs.imaging.commons.subpixel.LineExtractor;
import java.awt.image.BufferedImage;
import java.awt.*;
import java.io.File;
import java.util.Vector;
/**
* <p/>
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version,
* provided that any use properly credits the author.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details at http://www.gnu.org
* </p>
*
* @author Olly Oechsle, University of Essex, Date: 13-Mar-2008
* @version 1.0
*/
public class HoughPreview {
public static final int THRESHOLD = 50;
public static void main(String[] args) throws Exception {
String file = "pipes.png";
String filename = "/home/ooechs/Desktop/" + file;
PixelLoader original = new PixelLoader("/home/ooechs/Desktop/scaled_Frame1921.jpg");
BufferedImage image = javax.imageio.ImageIO.read(new File(filename));
HoughTransform h = new HoughTransform(image.getWidth(), image.getHeight());
FastStatistics s = new FastStatistics();
for (int i = 0; i < 1; i++) {
long start = System.currentTimeMillis();
h.initialise();
h.addPoints(image);
Vector<HoughLine> lines = h.getLines(THRESHOLD);
long end = System.currentTimeMillis();
long time = end - start;
System.out.println("Time: " + time);
s.addData(end - start);
}
System.out.println(s.getMean() + " +-" + s.getStandardDeviation());
h.initialise();
h.addPoints(image);
Vector<HoughLine> lines = h.getLines(THRESHOLD);
BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
for (int j = 0; j < lines.size(); j++) {
HoughLine houghLine = lines.elementAt(j);
HoughLine2 line = new HoughLine2(houghLine.theta, houghLine.r);
line.draw(image, newImage, Color.GREEN.getRGB());
if (line.valid) {
PixelLoader img = LineExtractor.extract(original, 50, line.start, line.end);
img.saveAs("/home/ooechs/Desktop/" + j + "_" + file);
}
}
//new PixelLoader(image).saveAs("/home/ooechs/Desktop/result_" + file);
//new ImageFrame(h.getHoughArrayImage());
new ImageFrame(newImage);
}
}