/* Initialize MAX1 maps */ void InitializeMAX1map() { int img, orient, x, y, here, i, trace[2]; /* calculate MAX1 maps and record the shifts */ pooledMax1map = float_matrix(numOrient, sizexSubsample*sizeySubsample); MAX1map = float_matrix(numImage*numOrient, sizexSubsample*sizeySubsample); trackMap = int_matrix(numImage*numOrient, sizexSubsample*sizeySubsample); startx = floor((halfFilterSize+1)/subsample)+1+locationShiftLimit; endx = floor((sizex-halfFilterSize)/subsample)-1-locationShiftLimit; starty = floor((halfFilterSize+1)/subsample)+1+locationShiftLimit; endy = floor((sizey-halfFilterSize)/subsample)-1-locationShiftLimit; for (x=startx; x<=endx; x++) for (y=starty; y<=endy; y++) { here = px(x, y, sizexSubsample, sizeySubsample); for (orient=0; orient<numOrient; orient++) { pooledMax1map[orient][here] = 0.; for (img=0; img<numImage; img++) { i = orient*numImage+img; MAX1map[i][here] = LocalMaximumPooling(img, orient, x*subsample, y*subsample, trace); trackMap[i][here] = trace[0]; pooledMax1map[orient][here] += MAX1map[i][here]; } } } }
/* computer MAX1 maps for image img */ void ComputeMAX1map(int img) { int orient, x, y, here, i, trace[2]; for (x=1; x<=sizexSubsample; x++) for (y=1; y<=sizeySubsample; y++) { here = px(x, y, sizexSubsample, sizeySubsample); for (orient=0; orient<numOrient; orient++) MAX1map[orient*numImage+img][here] = LocalMaximumPooling(img, orient, x*subsample, y*subsample, trace); } }
/* the local maximal Gabor inhibits overlapping Gabors */ void NonMaximumSuppression(int img, int mo, int mx, int my) { int x, y, orient, x1, y1, orient1, i, here, shift, startx0, endx0, starty0, endy0, trace[2]; float *f, maxResponse, maxResponse1; double *fc; /* inhibit on the SUM1 maps */ for (orient=0; orient<numOrient; orient++) { f = SUM1map[orient*numImage+img]; fc = Correlation[mo+orient*numOrient]; for (x=MAX(1, mx-2*halfFilterSize); x<=MIN(sizex, mx+2*halfFilterSize); x++) for (y=MAX(1, my-2*halfFilterSize); y<=MIN(sizey, my+2*halfFilterSize); y++) { f[px(x, y, sizex, sizey)] *= fc[px(x-mx+2*halfFilterSize+1, y-my+2*halfFilterSize+1, 4*halfFilterSize+1, 4*halfFilterSize+1)]; } } /* update the MAX1 maps */ startx0 = floor((mx-2*halfFilterSize)/subsample)-locationShiftLimit+1; starty0 = floor((my-2*halfFilterSize)/subsample)-locationShiftLimit+1; endx0 = floor((mx+2*halfFilterSize)/subsample)+locationShiftLimit; endy0 = floor((my+2*halfFilterSize)/subsample)+locationShiftLimit; for (orient=0; orient<numOrient; orient++) { i = orient*numImage+img; for (x=MAX(startx, startx0); x<=MIN(endx, endx0); x++) for (y=MAX(starty, starty0); y<=MIN(endy, endy0); y++) { /* go over the locations that may be affected */ here = px(x, y, sizexSubsample, sizeySubsample); maxResponse = MAX1map[i][here]; shift = trackMap[i][here]; orient1 = orientShifted[orient][shift]; x1 = x*subsample + xShift[orient][shift]; y1 = y*subsample + yShift[orient][shift]; if ((x1-mx>=-2*halfFilterSize)&&(x1-mx<=2*halfFilterSize)&& (y1-my>=-2*halfFilterSize)&&(y1-my<=2*halfFilterSize)) { /* if the previous local maximum is within the inhibition range */ if(Correlation[mo+orient1*numOrient] [px(x1-mx+2*halfFilterSize+1,y1-my+2*halfFilterSize+1,4*halfFilterSize+1,4*halfFilterSize+1)]==0.) { /* if it is indeed inhibited */ maxResponse1 = LocalMaximumPooling(img, orient, x*subsample, y*subsample, trace); trackMap[i][here] = trace[0]; MAX1map[i][here] = maxResponse1; pooledMax1map[orient][here] += (maxResponse1-maxResponse); } } } } }