/************************************************************************/ /* */ /* Program: clusterid.c */ /* Purpose: to identify clusters ("particles") in a 3-D */ /* segmented volume and remove those smaller than */ /* a user-specified volume */ /* Only applicable to a cubic (X * X * X) volume */ /* Input file: segemented 3-D image, one integer per line per */ /* voxel */ /* Output file: binary 3-D image, with values of 1 for particle */ /* (cluster) voxels and 0 otherwise */ /* Programmer: Dale P. Bentz */ /* National Institute of Standards and Technology */ /* 100 Bureau Drive Stop 8621 */ /* Gaithersburg, MD 20899-8621 */ /* Phone: (301) 975-5865 */ /* Fax: (301) 990-6891 */ /* E-mail: dale.bentz@nist.gov */ /* */ /* Date: 2001 */ /* */ /************************************************************************/ #include #include #include #define SYSSIZE 300 #define SYSSIZEP1 301 /* SYSSIZE plus one */ #define NUMPARTS 50000 /* maximum number of possible clusters */ #define POROSITY 0 #define ANHYDROUS 1 #define PRODUCTS 2 #define BURNT 8000 /* indicates burnt pixel during cluster identification */ /* array phase stores the microstructure representation */ static unsigned short int phase [SYSSIZEP1] [SYSSIZEP1] [SYSSIZEP1]; static int particle [SYSSIZEP1] [SYSSIZEP1] [SYSSIZEP1]; long int npixels[NUMPARTS]; short int pkeep[NUMPARTS]; /* routine to count phase fractions (porosity and solids) */ void phcount() { long int npore,nanhydrous,nproducts; int ix,iy,iz; npore=0; nanhydrous=nproducts=0; /* check all voxels in the 3-D system */ for(iz=0;iz=NUMPARTS){ printf("Too many particles, increase value of NUMPARTS! \n"); exit(1); } particle [ix] [iy] [iz]=iclust; /* store current pixel location */ nmat1+=1; xsum+=ix; ysum+=iy; zsum+=iz; xl1[nmat1]=ix; yl1[nmat1]=iy; zl1[nmat1]=iz; /* convert pixel ID to burnt */ phase [ix] [iy] [iz]=BURNT; ncount+=1; ccount+=1; bcount+=1; /* while new sites reamin for propagation */ while(ncount>0){ n2=0; nmat1=0; /* check all new site pixels for possible flood propagation */ for(n1=1;n1<=ncount;n1++){ /* read in location of next pixel site to be checked */ if(iw==1){ ixx=xl1[n1]; iyy=yl1[n1]; izz=zl1[n1]; } if(iw==2){ ixx=xl2[n1]; iyy=yl2[n1]; izz=zl2[n1]; } /* check 6 neighbors for flood propagation */ for(ic=1;ic<=6;ic++){ ix1=ixx; iy1=iyy; iz1=izz; switch (ic) { case 1: ix1=ixx-1; break; case 2: ix1=ixx+1; break; case 3: iy1=iyy-1; break; case 4: iy1=iyy+1; break; case 5: iz1=izz-1; break; case 6: iz1=izz+1; break; default: break; } /* if new site is in original box, then */ /* check for propagation */ /* note- no periodic boundaries are assumed */ if((ix1>=0)&&(ix1=0)&&(iy1=0)&&(iz1=8000){ printf("Error in burning too many new sources \n"); exit(1); } ccount+=1; bcount+=1; xsum+=ix1; ysum+=iy1; zsum+=iz1; particle[ix1][iy1][iz1]=iclust; if(iw==1){ xl2[n2]=ix1; yl2[n2]=iy1; zl2[n2]=iz1; } if(iw==2){ xl1[n2]=ix1; yl1[n2]=iy1; zl1[n2]=iz1; } phase [ix1] [iy1] [iz1]=BURNT; } } } } /* get ready for next cycle of the propagation */ ncount=n2; iw+=1; if(iw>2){iw=1;} } /* Compute particle centroid */ xcent=(float)xsum/(float)ccount; ycent=(float)ysum/(float)ccount; zcent=(float)zsum/(float)ccount; printf("Cluster %ld Size %ld \n",iclust,ccount); printf("Source= (%d, %d, %d) \n",ix,iy,iz); printf("Centroid= (%f, %f, %f) \n",xcent,ycent,zcent); npixels[iclust]=ccount; /* Tabulate statistics for particle greater than 2 voxels in volume */ if(ccount>=2){ ssum+=(float)ccount; s2sum+=((float)ccount*(float)ccount); } } } } } printf("Total pixels checked- %ld Clusters found- %ld \n",tcount,bcount); save=0.0; if(ssum>0.0){ save=s2sum/ssum; } printf("ssum count is %f \n",ssum); printf("Site weighted average cluster size- %f \n",save); /* Reconvert burnt areas to original phase */ for(iz=0;iz=sizecrit)){ iout=1; porcnt+=1; if(pkeep[tv]==0){ pkeep[tv]=1; nclusters+=1; } } fprintf(outfile,"%d\n",iout); } } } printf("Count for new solids is %ld out of %ld \n",porcnt,totcnt); printf("Count for clusters kept is %ld \n",nclusters); fclose(outfile); } main() { int i,nseed,menuch; /* Initialize arrays */ for(i=0;i