import java.awt.*; import java.awt.image.*; import java.applet.*; import java.net.*; import java.io.*; import java.lang.Math; import java.util.*; import java.awt.event.*; import javax.swing.*; import javax.swing.JApplet; import javax.imageio.*; import javax.swing.event.*; public class lineHough { int[] input; int[] output; float[] template={-1,0,1,-2,0,2,-1,0,1};; double progress; int width; int height; int[] acc; int accSize=30; int[] results; public void lineHough() { progress=0; } public void init(int[] inputIn, int widthIn, int heightIn) { width=widthIn; height=heightIn; input = new int[width*height]; output = new int[width*height]; input=inputIn; for(int x=0;x 0) && (r <= rmax)) acc[r*180+theta] = acc[r*180+theta] + 1; } } } } // now normalise to 255 and put in format for a pixel array int max=0; // Find max acc value for(r=0; r max) { //System.out.println("Value :" + acc[r*180+theta] + " " + theta); max = acc[r*180+theta]; } } } //System.out.println("Max :" + max); // Normalise all the values int value; for(r=0; r results[(accSize-1)*3]) { // add to bottom of array results[(accSize-1)*3] = value; results[(accSize-1)*3+1] = r; results[(accSize-1)*3+2] = theta; // shift up until its in right place int i = (accSize-2)*3; while ((i >= 0) && (results[i+3] > results[i])) { for(int j=0; j<3; j++) { int temp = results[i+j]; results[i+j] = results[i+3+j]; results[i+3+j] = temp; } i = i - 3; if (i < 0) break; } } } } double ratio=(double)(width/2)/accSize; System.out.println("top "+accSize+" matches:"); for(int i=accSize-1; i>=0; i--){ progress+=ratio; //System.out.println("value: " + results[i*3] + ", r: " + results[i*3+1] + ", theta: " + results[i*3+2]); drawPolarLine(results[i*3], results[i*3+1], results[i*3+2]); } return output; } // draw a line given polar coordinates (and an input image to allow drawing more than one line) private void drawPolarLine(int value, int r, int theta) { for(int x=0;x