12 #define abs(x) ((x)<0?-(x):x)
13 #define imgvec(img,x,y) (&((img)->imgary[(y)*(img)->twidth + x]))
15 #pragma init (init_object_module)
30 (elmtypeof(imgp)==ELM_FOREIGN)?
31 ((
unsigned char *)imgp->
c.
ivec.
iv[0]) :
37 piximg->tsize=piximg->twidth*piximg->theight;
40 piximg->wsize=piximg->width * piximg->height; }
45 {
register unsigned char *img=image->
imgary, *pat=pattern->imgary;
47 register int ww=pattern->width;
48 register long cor, corsum=0;
49 int tiw=image->twidth, piw=pattern->twidth;
50 int wh=pattern->height;
54 for (j=0; j<wh; j++) {
55 for (i=0; i<ww; i++) {
70 register int threshold;
73 {
register unsigned char *img=image->imgary, *pat=pattern->imgary;
76 register int tiw=image->twidth, piw=pattern->twidth;
77 register int ww=pattern->width;
78 register long cor, corsum;
79 register int wh=pattern->height;
82 for (
y=y0;
y<y0+size;
y++) {
83 for (
x=x0;
x<x0+size;
x++) {
88 for (j=0; j<wh; j++) {
89 for (i=0; i<ww; i++) {
91 if (cor>0) corsum+=cor;
93 if (corsum>threshold)
goto nextwindow;
97 if (corsum<threshold) {
98 if (debug) printf(
"cor=%ld (%d, %d)\n", corsum,
x,
y);
102 result->
x=
x; result->
y=
y;};
104 nextwindow:
continue;
118 x=ckintval(argv[2]);
y=ckintval(argv[3]);
131 int x,
y, cor, size, threshold;
132 struct {
long corval,
x,
y;} result;
136 x=ckintval(argv[2]); y=ckintval(argv[3]);
137 size=ckintval(argv[4]); threshold=ckintval(argv[5]);
152 {
unsigned char *pat1, *pat2, pat2x[1024*4];
153 int len, num_components, total_len, i, j, k, x, y;
154 int c, cor, min_cor, min_pos, max_cor, avecor, total_cor;
160 num_components=ckintval(argv[2]);
163 total_len=vecsize(argv[0]);
166 memcpy(&pat2x[0], pat2, total_len);
167 memcpy(&pat2x[total_len], pat2, total_len);
168 len=total_len/num_components;
173 min_pos = -1; min_cor=0x3fffffff; max_cor=0; total_cor=0;
175 for (i=0; i<len; i++) {
176 cor=0; x=i*num_components;
177 for (j=0; j<len; j++) {
178 c=0; y=j*num_components;
179 for (k=0; k<num_components; k++) c +=
abs(pat2x[x+j+k]-pat1[j+k]);
180 cor += c/num_components; }
181 if (cor < min_cor) { min_cor=cor; min_pos=i; }
182 else if (cor>max_cor) max_cor=cor;
184 fcorvec->
c.
fvec.
fv[i]=(float)cor/total_len;
187 vpush(
makeflt(min_cor/(flen*num_components)));
188 vpush(
makeflt(total_cor/(flen*num_components*flen)));
189 vpush(
makeflt(max_cor/(len*num_components)));