We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
my expandBlob code (Read 445 times)
my expandBlob code
Feb 9th, 2006, 4:05pm
 
so i am writing some blob detection code for school, and it is not performing very well. I think the root of the problem is something is wrong with my "expand blob" algorithem.

I have posted some code. If you could look over it and offer me any suggestions i would be greatly appreciative. Thank you!

void expandBlob(IPoint initialPoint, Blob curBlob){
markBuffer(initialPoint);
//Expand the x
boolean isGood=true;
IPoint myPoint=new IPoint(0,0);
myPoint=initialPoint;
println("currently examining this point " + myPoint.x + ","+ myPoint.y);
//Blob myBlob;
//myBlob=curBlob;
while(isGood){
 myPoint.x+=1;
 
 if (isBlob(myPoint)){
   curBlob.size+=1;
   
   if (curBlob.upperRight.x<myPoint.x){
     curBlob.upperRight.x=myPoint.x;
   }
   if (curBlob.lowerRight.x<myPoint.x){
     curBlob.lowerRight.x=myPoint.x;
   }
   expandBlob(myPoint, curBlob);
 
 }
 
 else {isGood=false;}
 markBuffer(myPoint);
}

//expand the y
isGood=true;
myPoint=initialPoint;
while(isGood){
 myPoint.y+=1;
 if (isBlob(myPoint)){
   curBlob.size+=1;
   
   if (curBlob.upperRight.y<myPoint.y){
     curBlob.upperRight.y=myPoint.y;
   }
   if (curBlob.lowerRight.y<myPoint.y){
     curBlob.lowerRight.y=myPoint.y;
   }
   expandBlob(myPoint, curBlob);
 
 }
 
 else {isGood=false;}
 markBuffer(myPoint);
}

//Now we need to shrink x and y
 //shrink the y
isGood=true;
myPoint=initialPoint;
while(isGood){
 myPoint.y-=1;
 if (isBlob(myPoint)){
   curBlob.size+=1;
   
   if (curBlob.upperRight.y<myPoint.y){
     curBlob.upperRight.y=myPoint.y;
   }
   if (curBlob.lowerRight.y<myPoint.y){
     curBlob.lowerRight.y=myPoint.y;
   }
   expandBlob(myPoint, curBlob);
 
 }
   else {isGood=false;}
 markBuffer(myPoint);
}
   //shrink the x
isGood=true;
myPoint=initialPoint;
while(isGood){
 myPoint.x-=1;
 if (isBlob(myPoint)){
   curBlob.size+=1;
   
   if (curBlob.upperRight.x<myPoint.x){
     curBlob.upperRight.x=myPoint.x;
   }
   if (curBlob.lowerRight.x<myPoint.x){
     curBlob.lowerRight.x=myPoint.x;
   }
   expandBlob(myPoint, curBlob);
 
 }
 


 
 else {isGood=false;}
 markBuffer(myPoint);
}


if (curBlob.size > finalBlob.size){
  finalBlob=curBlob;
}
 

 
}
Page Index Toggle Pages: 1