1 | /* |
---|
2 | patch_match.c implements ... |
---|
3 | |
---|
4 | takes two images and does sum of differences of intensities at windows specified in each |
---|
5 | |
---|
6 | 2001 written by Phil Torr |
---|
7 | Microsoft Research Cambridge |
---|
8 | */ |
---|
9 | |
---|
10 | //if correlation exceeds jump out then stop |
---|
11 | #include <math.h> |
---|
12 | #include <stdio.h> |
---|
13 | #include "mex.h" |
---|
14 | |
---|
15 | void mexFunction ( |
---|
16 | int nlhs, /* number of expected outputs */ |
---|
17 | mxArray **plhs, /* matrix pointer array returning outputs */ |
---|
18 | int nrhs, /* number of inputs */ |
---|
19 | const mxArray **prhs /* matrix pointer array for inputs */ |
---|
20 | ) { |
---|
21 | int width, height, i, j, l, k, border =1; |
---|
22 | double *out, *im1, *im2; |
---|
23 | bool is_max; |
---|
24 | int x1,y1,x2,y2,x1i,y1i,x2i,y2i,half_size,jump_out; |
---|
25 | double corr = 0.0; |
---|
26 | |
---|
27 | /* parameter checks */ |
---|
28 | if ((nrhs < 7) || (nlhs != 1)) { |
---|
29 | mexErrMsgTxt ("Usage: Y = patch_match(im1,im2,x1,y1,x2,y2,half_size,jump_out)\n\n"); |
---|
30 | return; |
---|
31 | } |
---|
32 | |
---|
33 | |
---|
34 | //not any checking here yet!!!! |
---|
35 | |
---|
36 | /* reading the parameters */ |
---|
37 | height = mxGetM (prhs [0]); |
---|
38 | width = mxGetN (prhs [0]); |
---|
39 | im1 = (double *) mxGetPr (prhs [0]); |
---|
40 | im2 = (double *) mxGetPr (prhs [1]); |
---|
41 | x1 = (int)(mxGetScalar(prhs[2]))-1; |
---|
42 | y1 = (int)(mxGetScalar(prhs[3]))-1; |
---|
43 | x2 = (int)(mxGetScalar(prhs[4]))-1; |
---|
44 | y2 = (int)(mxGetScalar(prhs[5]))-1; |
---|
45 | half_size = (int)(mxGetScalar(prhs[6])); |
---|
46 | jump_out = (double)(mxGetScalar(prhs[7])); |
---|
47 | |
---|
48 | // printf("x1 y1 x2 y2 %d %d %d %d\n",x1,y1 ,x2,y2); |
---|
49 | |
---|
50 | //out = mxGetScalar(plhs [0]); |
---|
51 | |
---|
52 | /* require memory for return */ |
---|
53 | plhs [0] = mxCreateDoubleMatrix (1, 1, mxREAL); |
---|
54 | out = (double *) mxGetPr (plhs [0]); |
---|
55 | |
---|
56 | |
---|
57 | // do correlation over a patch |
---|
58 | for (i = -half_size; i <= half_size; i++) |
---|
59 | { |
---|
60 | for (j = -half_size; j <= half_size; j++) |
---|
61 | { |
---|
62 | x1i = x1 + i; |
---|
63 | x2i = x2 + i; |
---|
64 | |
---|
65 | y1i = y1 + j; |
---|
66 | y2i = y2 + j; |
---|
67 | corr += fabs(im1 [y1i * height + x1i]- im2 [y2i * height + x2i]); |
---|
68 | // printf("im1 i j x1i y1i %d %d %d %d %lf \n", i,j,x1i,y1i,im1 [x1i * height + y1i]); |
---|
69 | // printf("im2 i j x2i y2i %d %d %d %d %lf \n", i,j,x2i,y2i,im2 [x2i * height + y2i]); |
---|
70 | // printf("corr i j %d %d %lf \n", i,j,corr); |
---|
71 | |
---|
72 | } |
---|
73 | if (corr > jump_out) |
---|
74 | { |
---|
75 | out[0] = corr; |
---|
76 | return; |
---|
77 | } |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | out[0] = corr; |
---|
82 | |
---|
83 | // printf("corr \n %lf", corr); |
---|
84 | |
---|
85 | return; |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | // out[0] = im1 [x1 * height + y1]- im2 [x2 * height + y2]; |
---|
91 | // out[0] = im1 [y1 * height + x1]- im2 [y2 * height + x2]; |
---|
92 | // out[0] = im1 [y1 * width + x1]- im2 [y2 * width + x2]; |
---|