Definition at line 483 of file ColorSegmentation.h. References Impala::Core::Array::pixgroup::idx, Impala::Core::Array::pixgroup::nrPixInGroup, and UNLABELED. Referenced by ColorSegmentation(). 00485 { 00486 long imsize = width*height; 00487 int x,y; 00488 long i; 00489 int d[4] = {1, -width, -1, width}; 00490 00491 //remove pixels at the boundary of a region (thickness = 2*numpixrm) 00492 for (int l=numpixrm; l>0; l--) 00493 { 00494 // make a copy of the clusterMap, to keep the state a pixel is in. 00495 VectorDouble pixstate(clusterMap) ; 00496 00497 // start after the borderline (first line of pixels) 00498 i = width ; 00499 for (y=1; y<height-1; y++) { 00500 // skip left-border pixel 00501 i++; 00502 for (x=1; x<width-1; x++) { 00503 if (clusterMap[i]!=UNLABELED) { 00504 00505 bool boundary = false; 00506 for (int u=0; u<4; u++) { 00507 // if right,top,left or bottom pixel is from another 00508 // region, or unlabelled 00509 if (clusterMap[i+d[u]]!=clusterMap[i]) { 00510 boundary = true; break; 00511 } 00512 } 00513 if (boundary) pixstate[i] = UNLABELED; //remove from region 00514 } 00515 i++; 00516 } // end for(x) 00517 00518 // skip right-border pixel 00519 i++; 00520 } // end for(y) 00521 00522 // set the result to clusterMap 00523 clusterMap = pixstate; 00524 } 00525 00526 // renumber the leftover regions 00527 for (i=0; i<nrClusters; i++) rg[i].nrPixInGroup = 0; 00528 for (i=0; i<imsize; i++) 00529 if (clusterMap[i] != UNLABELED) { 00530 int lb = clusterMap[i]; 00531 rg[lb].idx[rg[lb].nrPixInGroup] = i; 00532 rg[lb].nrPixInGroup++; 00533 } 00534 00535 // UNLABEL the regions that are too small 00536 int count = 0; 00537 for (int c=0; c<nrClusters; c++) { 00538 if (rg[c].nrPixInGroup >= sizethreshold) { 00539 for (i=0; i<rg[c].nrPixInGroup; i++) clusterMap[rg[c].idx[i]] = count; 00540 count++; 00541 } 00542 else for (i=0; i<rg[c].nrPixInGroup; i++) clusterMap[rg[c].idx[i]] = UNLABELED; 00543 } 00544 00545 // store the new number of regions. 00546 nrClusters = count; 00547 }
|