|
|
Description
This applet demonstrates recursive connected component
labeling using a binary image on a pseudo screen.
Click on a pixel on the pseudo screen to interactively set or clear a pixel. This way you can either connect a few
shapes together, or convert a shape into two disconnected regions.
Code
(8-Connected Component Labeling)
|
void 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); } |