Results 1 to 2 of 2
  1. #1
    Mazharul is offline Member
    Join Date
    Aug 2008
    Posts
    12
    Rep Power
    0

    Default Stack class/problem in stackSize Initialization and usage of pop() function

    Java Code:
    Sir,
      I want to implement [COLOR="Blue"]"Connected component labelling algo"[/COLOR] by using stack data structure.Problem arises at the moment of Stack initialization and at the time of pop() function usage:
    
    Following is the class definition:
    Jcreator gives two error:
     1) incompatible types
     2) cannot find symbol contructor Stack(int)
    
    .........I can not find the error...........Plz help..........
    OR
    Can any one give me a new fresh code of Copnnected Component labelling;
    //////////////////////////////////////////////////////////////////////////////////
    
    import java.util.*;
    
    class LabelImage
    {
    	
    	
    	int [][] label ;
        Stack stack ;
        
    /** Creates a new instance of LabelImage */
       public LabelImage() 
       {
       }
     	
     public int[][] labelImage(int[][] img, int stackSize)
        {
        	
        int nrow = img.length ;
        int ncol = img[0].length ;
        int lab = 1 ;
        int [] pos;
        
        	
        stack = new Stack( stackSize ) ;
        label = new int[nrow][ncol] ;
        
        
          for (int r = 1; r < nrow-1; r++)
             for (int c = 1; c < ncol-1; c++) {
             	
              if (img[r][c] == 0) continue ;
               if (label[r][c] > 0) continue ;
               
            /* encountered unlabeled foreground pixel at position r, c */
           /* push the position on the stack and assign label */
           
              stack.push(new int [] {r, c}) ;
              label[r][c] = lab ;
        
        
             /* start the float fill */
                 while ( !stack.isEmpty()) {
                      pos= stack.pop() ;
                       
                       int i = pos[0]; 
                       int j = pos[1];
                       
                       
                       if (img[i-1][j-1] == 1 && label[i-1][j-1] == 0) 
                       {
                         stack.push( new int[] {i-1,j-1} );
                         label[i-1][j-1] = lab ;
                       }
                       
                       
                       
                       if (img[i-1][j] == 1 && label[i-1][j] == 0)
                        {
                         stack.push( new int[] {i-1,j} );
                         label[i-1][j] = lab ;
                         }
                         
                         if (img[i-1][j+1] == 1 && label[i-1][j+1] == 0) 
                         {
                          stack.push( new int[] {i-1,j+1} );
                          label[i-1][j+1] = lab ;
                         }
                       
                       if (img[i][j-1] == 1 && label[i][j-1] == 0)
                        {
                         stack.push( new int[] {i,j-1} );
                         label[i][j-1] = lab ;
                        }
                       
                       if (img[i][j+1] == 1 && label[i][j+1] == 0) 
                       {
    
                         stack.push( new int[] {i,j+1} );
                         label[i][j+1] = lab ;
                       }
                       
                       
                       if (img[i+1][j-1] == 1 && label[i+1][j-1] == 0)
                        {
                        stack.push( new int[] {i+1,j-1} );
                        label[i+1][j-1] = lab ;
                        }
                        
                        
                        if (img[i+1][j] == 1 && label[i+1][j] == 0) 
                        {
                         stack.push( new int[] {i+1,j} );
                          label[i+1][j] = lab ;
                         }
                        
                        if (img[i+1][j+1] == 1 && label[i+1][j+1] == 0) 
                        {
                          stack.push( new int[] {i+1,j+1} );
                          label[i+1][j+1] = lab ;
                        }
                       
                      } /* end while */ 
                       
                      lab++ ;
                      }
                       
                       return label ;
                       
                   }
                   
                   //end of labelImage() function
    
                }
    
    ///////////////////////////////////////////////////////////////////////

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Register a callback function in other class
    By barts2108 in forum New To Java
    Replies: 2
    Last Post: 11-10-2008, 04:24 PM
  2. Demonstration of Stack class in java.util package
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:33 PM
  3. How to use Stack class in java.util package
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:32 PM
  4. initialization value problem
    By ravian in forum New To Java
    Replies: 2
    Last Post: 01-28-2008, 10:54 AM
  5. Icon initialization problem
    By saz25 in forum AWT / Swing
    Replies: 1
    Last Post: 12-24-2007, 10: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
  •