CS6825: Computer Vision word cloud

Blob Detection

In the case of a binary image, shown below:

blob = connected region of "on" symbols.

4 blobs that are 8-connected!

Go to http://www.cosc.canterbury.ac.nz/mukundan/covn/Label.html for an Applet that does component labeling

Algorithm 1 -Recursive

1.Initialize your label image with no labels for all pixels.
2.Scan your binary image and find the first non-zero pixel, that has no label.  Create a label for it in the label image.
3.Find all unmarked non-zero neighbors and mark them as visited with the same label id.
4.For each of these neighbors, go to step 3.

5.Repeat step 2 until you have scanned the entire image.

ALGORITHM version a (here labeling where blob /object point has thresholded value of 0 in the binary image)

oid compLabel(int i, int j,int m){
  if(getPixel(i,j)==0){
   setPixel(i,j,m);
   compLabel(i-1,j-1,m);
   compLabel(i-1,j,m);
   compLabel(i-1,j+1,m);
   compLabel(i,j-1,m);
   compLabel(i,j+1,m);
   compLabel(i+1,j-1,m);
   compLabel(i+1,j,m);
   compLabel(i+1,j+1,m);
  }
}

void beginLabel(){
  int m=0;
  for(int y=0; y < size; y++)
   for(int x=0; x < size; x++)
    if(getPixel(x,y)==0)
     compLabel(x,y,++m);
}

 

ALRGORITHM version b (here labeling where blob /object point has thresholded value of 1 in the binary image)

void setLabels(){
  int m=2; //scr is a pseudo screen object
  for(int y=0; y<scr.hgt; y++)
  for(int x=0; x<scr.wid; x++)
    if(scr.getPixel(x,y)==1) compLabel(x,y,m++);
}

void compLabel(int i, int j,int m){
  if(scr.getPixel(i,j)==1){
    scr.setPixel(i,j,m); //assign label
    slow(); //thread delay
    compLabel(i-1,j-1,m); compLabel(i-1,j,m);
    compLabel(i-1,j+1,m); compLabel(i,j-1,m);
    compLabel(i,j+1,m); compLabel(i+1,j-1,m);
    compLabel(i+1,j,m); compLabel(i+1,j+1,m);
  }
}

Algorithm 2 -Iterative

Scan the array, raster fashion.

When a non-zero pixel is found, look above and to left for other non-zero pixels and if one is found, join the current pixel to this blob. Join blobs at the bottom of U's.

 

algorithm TwoPass(data)     
linked = []     
labels = structure with dimensions of data, initialized with the value of Background          

First pass         
 for row in data:        
 for column in row:            
   if data[row][col] is not Background                                 
       neighbors = connected elements with the current element's label         
       
       if neighbors is empty            linked[NextLabel] = set containing NextLabel labels[row][column] = NextLabel            NextLabel += 1        else            Find the smallest label            L = neighbors labels
           labels[row][column] = min(L)            for label in L
              linked[label] = union(linked[label], L)
Second pass
 for row in data
 for column in row
   if
labels[row][column] is not Background
      labels[row][column] = min(linked[labels[row][column]])
 return labels labeling steps



© Lynne Grewe