Results 1 to 1 of 1
  1. #1
    syarizma is offline Member
    Join Date
    Aug 2009
    Posts
    21
    Rep Power
    0

    Cool 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 07:22 AM.

Similar Threads

  1. request detection
    By mtyoung in forum Advanced Java
    Replies: 6
    Last Post: 02-05-2009, 04:46 AM
  2. Hough transform...........
    By Mazharul in forum Java 2D
    Replies: 1
    Last Post: 01-22-2009, 12:43 AM
  3. brightest red spot detection
    By Bharat in forum New To Java
    Replies: 0
    Last Post: 01-15-2009, 04:21 PM
  4. USB Detection
    By alanixu in forum New To Java
    Replies: 3
    Last Post: 11-12-2008, 05:04 PM
  5. IE Browser Proxy detection
    By bhopalpal in forum Networking
    Replies: 0
    Last Post: 08-21-2008, 03:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •