FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Video, Camera
(Moderator: REAS)
   Connected components
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Connected components  (Read 839 times)
gabon

WWW
Connected components
« on: Nov 5th, 2004, 9:06am »

I don't know if it is the right forum, anyway, I'm experimenting a little bit on computer-vision and I'm trying to learn the notions about image processing. Now I'm trying to use the connected component algorithm http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/OWENS/LECT3/node 2.html#SECTION00021000000000000000
but obviously I can't make it work.
Instead to use just flags I went straight using colors, so the conceptual calculate is:
 
Code:

if(A == black){
 do nothing;
}else if(D != black){
 A = D;
}else if(B == black && C == black){
 color++;
 A = color;
// Here an issue
}else if(B != black || C != black){
 A = color;
 // I tried also A = B; or A = C;
}else if(B != black && C != black){
 if(B = C){
  A = B;
 }else{
  B = C = A;
 }
}

 
Does someone see the mistake?
 
Thank you very much, chr
 
 
zach


Re: Connected components
« Reply #1 on: Nov 5th, 2004, 12:48pm »

I'm not sure about errors, but my students just did connected components in my computer vision class.  they recreated the algorithm described quite well by David Eberly inside of this code:
 
http://www.magic-software.com/Source/ImageAnalysis/WmlBinary2D.cpp
 
It works by labeling groups across the horizontal, then linking the horizontal groups together in a very clever way.
 
maybe this can help?
 
- zach  
 
gabon

WWW
Re: Connected components
« Reply #2 on: Nov 5th, 2004, 1:23pm »

Also mine works in scrolling pixels[], we can say. The code of your students seems little bit more complex either to read and to apply. There is a big difference between P5 and C, so I would like to keep it lighter as possible.
 
Thank you very much anyway
 
 
chr
 
zach


Re: Connected components
« Reply #3 on: Nov 5th, 2004, 10:41pm »

actually, the code has a straightforward description in the comments which could be pretty easily implemented in java...
 
gabon

WWW
Re: Connected components
« Reply #4 on: Nov 7th, 2004, 12:52pm »

I found an other algorithm, that works better but not perfectly. So starting from a b/w image at 1 bit I've implemented in this way:
 
Code:

labels = new int[npixels];
for(int i=0; i<npixels; i++){
 if(pixels[i]==black){
  labels[i]=0;
 }else{
  labels[i]=1;
 }
}
//
int NewLabel=0;
int row,rowt,rowb;
int lp,lq;
int lx=1;
for(int y=1; y<h; y++){
 row=y*w;
 rowt=(y-1)*w;
 for(int x=1; x<w; x++){
  if(pixels[row+x]==white){
   lp=labels[rowt+x];
   lq=labels[row+(x-1)];
   if(lp == 0 && lq == 0) {
    NewLabel++;
    lx = NewLabel;
   }else if((lp != lq)&&(lp != 0)&&(lq != 0)){
    lx = lq;
   }else if(lq != 0){
    lx = lq;
   }else if(lp != 0){
    lx = lp;
   }
   labels[row+x] = lx;
  }
 }
}
println(NewLabel);
for(int i=0; i<npixels; i++){
 pixels[i]=color(labels[i],labels[i],labels[i]);
}

 
very strange... thx, chr
 
Pages: 1 

« Previous topic | Next topic »