Results 1 to 1 of 1
- 08-11-2009, 06:14 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 21
- Rep Power
- 0
Line detection using Hough Transform
hi..
Here, the code to convert the image into binary(Binary_image.java).Now, i need help to code the program for line detection of the binary image .
Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.image.*; import java.awt.Image.*; public class Binary_Image extends JApplet{ Image img; int iw,ih; int pixels[]; int cnt1=0,cnt=0,cnt2=0; public void init() { try { ImageIcon imageIcon = new ImageIcon("jawi.gif"); Image img = imageIcon.getImage(); iw = img.getWidth(null); ih = img.getHeight(null); pixels = new int[iw*ih]; PixelGrabber pg = new PixelGrabber(img,0,0,iw,ih,pixels,0,iw); pg.grabPixels(); } catch(InterruptedException e) {}; for(int i=0;i<iw*ih;i++) { int p = pixels[i]; int r = (p>>16) & 0xff; int g = (p>>8) & 0xff; int b = (p) & 0xff; int k = (int)(.56*g + .33*r + .11 * b); cnt++; if(k<36) { cnt1++; pixels[i]=(255 << 24)|(0 << 16)|(0 << 8)|0; } else { cnt2++; pixels[i]=(255 << 24)|(255 << 16)|(255 << 8)|255; } } //System.out.println("Total no of pixels ="+cnt); System.out.println("Total no of black pixels ="+cnt1); //System.out.println("Total no of white pixels ="+cnt2); img = createImage(new MemoryImageSource(iw,ih,pixels,0,iw)); //double [][]ImgArr =new double[50][50] ; } public static void main(String[]args) { JFrame frame = new JFrame (); Binary_Image applet = new Binary_Image(); frame.add(applet,BorderLayout.CENTER); applet.init(); frame.setSize(500,300); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(false); } }
The algorithm as follows:
1.0 Define the Hough Transform ρmin, ρmax, θmin, and θmax.
2.0 Quantify the ρ-θ plane into cells by formatting an accumulator cells array A(ρ,θ) where ρ is between ρmin and ρmax and θ is between θmin to θmax.
3.0 Initialize each element of an accumulator cell array A to zero.
4.0 For each black pixel in a binary image, perform the following:
4.1 For each value of θ from θmin to θmax , calculate the corresponding ρ using equation:
ρ = x cos θ + y sin θ
4.2 Round off the ρ value to the nearest interval value.
4.3 Increment the accumulator array element A (ρ, θ).
4.4 Detect best line candidates as local maxima in an accumulator cell array.Last edited by syarizma; 08-11-2009 at 06:22 AM.
Similar Threads
-
request detection
By mtyoung in forum Advanced JavaReplies: 6Last Post: 02-05-2009, 03:46 AM -
Hough transform...........
By Mazharul in forum Java 2DReplies: 1Last Post: 01-21-2009, 11:43 PM -
brightest red spot detection
By Bharat in forum New To JavaReplies: 0Last Post: 01-15-2009, 03:21 PM -
USB Detection
By alanixu in forum New To JavaReplies: 3Last Post: 11-12-2008, 04:04 PM -
IE Browser Proxy detection
By bhopalpal in forum NetworkingReplies: 0Last Post: 08-21-2008, 02:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks