#include "stdio.h" #include "setup.h" void getnbhd(i,j,ns,nbvec,typevec,n,m,nsites) /************************************************************************* returns the neighbors of the ijth cell of the image. nbvec[4] points to the neighboring sites (uses vectorized sites). imkey[n][m] holds the "active" pixels 0-active 1-inactive xmap[n][m] maps the image sites (i,j) to vector sites k = 0,...,NSITES ***********************************************************************/ int *ns, i, j, *nbvec, *typevec, n, m, nsites; { /* third order neighborhood: */ static int searchkey[12][3] = { 1, 1, 3, 0, 1, 2, -1, 1, 3, -1, 0, 1, -1,-1, 3, 0,-1, 2, 1,-1, 3, 1, 0, 1, 2, 0, 4, -2, 0, 4, 0, 2, 4, 0,-2, 4}; /* second order neighborhood static int searchkey[16][3] = { 1, 1, 3, 0, 1, 2, -1, 1, 3, -1, 0, 1, -1,-1, 3, 0,-1, 2, 1,-1, 3, 1, 0, 1, 1, 1, 3, 0, 1, 2, -1, 1, 3, -1, 0, 1, -1,-1, 3, 0,-1, 2, 1,-1, 3, 1, 0, 1}; */ /* First order neighborhoods static int searchkey[8][3] = { 0, 1, 2, -1, 0, 1, 0,-1, 2, 1, 0, 1, 0, 1, 2, -1, 0, 1, 0,-1, 2, 1, 0, 1}; */ int ii,jj,ival,jval,count, nbmatrix[16][3]; for(ii=0;ii<12;ii++){ nbmatrix[ii][0] = i - searchkey[ii][0]; nbmatrix[ii][1] = j - searchkey[ii][1]; nbmatrix[ii][2] = searchkey[ii][2]; } *ns = 12; count = 12; /* remove adjacencies that go off imagekey */ ii = -1; while(count) { ii++; count--; ival = nbmatrix[ii][0]; jval = nbmatrix[ii][1]; if(ival < 0 || ival>=n || jval<=-1 || jval>=m) { /* remove and adjust remaining */ for(jj=ii;jj<12;jj++) { nbmatrix[jj][0] = nbmatrix[jj+1][0]; nbmatrix[jj][1] = nbmatrix[jj+1][1]; nbmatrix[jj][2] = nbmatrix[jj+1][2]; } ii--; *ns -= 1; } } for(ii=0;ii<*ns;ii++){ nbvec[ii] = nbmatrix[ii][0]*m + nbmatrix[ii][1]%m; typevec[ii] = nbmatrix[ii][2]; } }