www.pudn.com > jseg.rar > reggrow.c
#include#include #include #include #include "mathutil.h" #include "imgutil.h" #include "memutil.h" #include "ioutil.h" #include "segment.h" int getrmap3(short *rmap,float *J,int ny,int nx,float *threshJ1,int TR,float RSIZE, unsigned char *rmap0,int n2bgrow,float *threshJ2,int oldTR,int *appear) { float *threshJ3; short *rmap1[TN]; int j,k,l,TR2[TN],index[TN],imgsize; imgsize = ny*nx; threshJ3=(float *)calloc(oldTR+1,sizeof(float)); for (k=0;k TR) { for (l=0;l TR) { if (iy-1>=0) { loc1 = loc-nx; if (rmap[loc]!=rmap[loc1] && rmap0[loc]==rmap0[loc1]) checkneigh(rmap[loc],rmap[loc1],neigh,neighn); } if (ix-1>=0) { loc1 = loc-1; if (rmap[loc]!=rmap[loc1] && rmap0[loc]==rmap0[loc1]) checkneigh(rmap[loc],rmap[loc1],neigh,neighn); } if (ix+1 TR) { if (neighn[rmap[l]]==1) rmap[l]=neigh[rmap[l]]; else rmap[l]=0; } } free(neigh); free(neighn); rmap += imgsize; rmap0 += imgsize; J += imgsize; } free(threshJ1); free(threshJ2); return alldone; } void flood(short *rmap1,float *J0,int nt,int ny,int nx,unsigned char *rmap00, int oldTR,int **done) { int it,iy,ix,*x,*y,M,M0,*index,i,j,k,l,imgsize,loc,loc1; float *buf,*J; BOUND *bd; short *neigh,*rmap; unsigned char *rmap0; rmap = rmap1; rmap0 = rmap00; J = J0; imgsize = ny*nx; neigh=(short *)calloc(imgsize,sizeof(short)); for (it=0;it 0) { buf[M]=J[loc]; y[M]=iy; x[M]=ix; M++; } } else neigh[loc]=rmap[loc]; } loc ++; } } index = (int *)calloc(M,sizeof(int)); piksrtS2B(M,buf,index); bd = (BOUND *)calloc(M0,sizeof(BOUND)); for (i=0;i 0) { iy=bd[0].by; ix=bd[0].bx; loc = LOC2(iy,ix,nx); rmap[loc]=neigh[loc]; for (i=1;i =0) { loc1 = loc-nx; if (neigh[loc1]==0 && rmap0[loc]==rmap0[loc1]) { neigh[loc1]=rmap[loc]; for (i=0;i J[loc1]) break; } for (j=M-1;j>=i;j--) bd[j+1]=bd[j]; bd[i].bJ=J[loc1]; bd[i].by=iy-1; bd[i].bx=ix; M++; } } if (ix-1>=0) { loc1 = loc-1; if (neigh[loc1]==0 && rmap0[loc]==rmap0[loc1]) { neigh[loc1]=rmap[loc]; for (i=0;i J[loc1]) break; } for (j=M-1;j>=i;j--) bd[j+1]=bd[j]; bd[i].bJ=J[loc1]; bd[i].by=iy; bd[i].bx=ix-1; M++; } } if (ix+1 J[loc1]) break; } for (j=M-1;j>=i;j--) bd[j+1]=bd[j]; bd[i].bJ=J[loc1]; bd[i].by=iy; bd[i].bx=ix+1; M++; } } if (iy+1 J[loc1]) break; } for (j=M-1;j>=i;j--) bd[j+1]=bd[j]; bd[i].bJ=J[loc1]; bd[i].by=iy+1; bd[i].bx=ix; M++; } } } free(bd); } rmap += imgsize; rmap0 += imgsize; J += imgsize; } free(neigh); } void getneigh(short *neigh,float *J,int ny,int nx,int iy,int ix,short *rmap, unsigned char *rmap0,int loc) { float diff,neighJ=100.0; int loc1; if (iy-1>=0) { loc1 = loc-nx; if (rmap[loc1]>0 && rmap0[loc]==rmap0[loc1]) { if (neigh[loc]>0) { diff = fabs(J[loc]-J[loc1]); if (diff =0) { loc1 = loc-1; if (rmap[loc1]>0 && rmap0[loc]==rmap0[loc1]) { if (neigh[loc]>0) { diff = fabs(J[loc]-J[loc1]); if (diff 0 && rmap0[loc]==rmap0[loc1]) { if (neigh[loc]>0) { diff = fabs(J[loc]-J[loc1]); if (diff 0 && rmap0[loc]==rmap0[loc1]) { if (neigh[loc]>0) { diff = fabs(J[loc]-J[loc1]); if (diff 0) { if (iy-1>=0) { loc1 = loc-nx; if (rmap0[loc]==rmap0[loc1]) checkneigh(rmap2[loc],rmap1[loc1],neigh,neighn); } if (ix-1>=0) { loc1 = loc-1; if (rmap0[loc]==rmap0[loc1]) checkneigh(rmap2[loc],rmap1[loc1],neigh,neighn); } if (ix+1 0) { if (neighn[rmap2[l]]==1) rmap1[l]=neigh[rmap2[l]]; } } free(neigh); free(neighn); rmap1 += imgsize; rmap0 += imgsize; } free(rmap2); } int rmapgrow2(short *rmap,int *ky,int *kx,int j,int ny,int nx,unsigned char *rmap0, int *kl) { int loc1,grow,iy,ix,loc; iy = *ky; ix = *kx; loc = *kl; grow = 0; rmap[loc]=j; if (iy-1>=0) { loc1 = loc-nx; if (rmap[loc1]==-1 && rmap0[loc]==rmap0[loc1]) { if (grow == 0) { *ky = iy-1; *kx = ix; *kl = loc1; grow = 1; } rmap[loc1] = -100; } } if (ix-1>=0) { loc1 = loc-1; if (rmap[loc1]==-1 && rmap0[loc]==rmap0[loc1]) { if (grow == 0) { *ky = iy; *kx = ix-1; *kl = loc1; grow = 1; } rmap[loc1] = -100; } } if (ix+1 0) { if (neighn[rmap2]==0) { neigh[rmap2]=rmap1; neighn[rmap2]=1; } else if (neighn[rmap2]==1) { if (rmap1!=neigh[rmap2]) neighn[rmap2]=-1; } } } int getrmap1(short *rmap,float *J,int ny,int nx,float *threshJ,int TR,float RSIZE, unsigned char *rmap0,int n2bgrow) { int i,j,k,l,iy,ix,*count,*convert,newTR,loc,loc1,imgsize,grow,jy,jx; int grow1,ky,kx,kl; float threshJ1; imgsize = ny*nx; j=0; loc=0; for (iy=0;iy 0) { count = (int *) calloc(newTR+1,sizeof(int)); for (l=0;l TR) count[rmap[l]]++; } convert=(int *)calloc(newTR+1,sizeof(int)); for (i=1;i<=newTR;i++) convert[i]=i; for (i=TR+1;i<=j+TR;i++) { if (count[i] convert[i]) convert[k]--; } convert[i]=n2bgrow; newTR--; } } for (l=0;l TR) rmap[l]=convert[rmap[l]]; } free(convert); free(count); } return newTR; } int rmapgrow1(short *rmap,int *ky,int *kx,int i,int j,int ny,int nx,float *J, float threshJ,unsigned char *rmap0,int imgsize,int *kl) { int loc1,grow,iy,ix,loc; iy = *ky; ix = *kx; loc = *kl; grow = 0; rmap[loc]=j; if (iy-1>=0) { loc1 = loc-nx; if (rmap[loc1]==i && J[loc1]<=threshJ && rmap0[loc]==rmap0[loc1]) { if (grow == 0) { *ky = iy-1; *kx = ix; *kl = loc1; grow = 1; } rmap[loc1] = -100; } } if (ix-1>=0) { loc1 = loc-1; if (rmap[loc1]==i && J[loc1]<=threshJ && rmap0[loc]==rmap0[loc1]) { if (grow == 0) { *ky = iy; *kx = ix-1; *kl = loc1; grow = 1; } rmap[loc1] = -100; } } if (ix+1