source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/torr/torr_birch_match.c @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 2.9 KB
Line 
1/*
2patch_match.c     implements ...
3
4  use a modified 2d version of the birchfield and tomasi algorithm
5
6  needs as input
7
8  in right image we take three images:
9
10  max round pixel
11  min round pixel
12  pixel
13
14  and left image
15
16  plus x,y location in each image
17  plus half_size
18
19  2001 written by Phil Torr
20  Microsoft Research Cambridge
21*/
22
23//if correlation exceeds jump out then stop
24#include <math.h>
25#include <stdio.h>
26#include "mex.h"
27
28void mexFunction (
29                                  int           nlhs,              /* number of expected outputs */
30                                  mxArray       **plhs,            /* matrix pointer array returning outputs */
31                                  int           nrhs,              /* number of inputs */
32                                  const mxArray **prhs     /* matrix pointer array for inputs */
33                                  ) {
34        int       width, height, i, j, l, k, border =1;
35        double    *out, *im1, *im2, *max_im2, *min_im2;
36        bool is_max;
37        int x1,y1,x2,y2,x1i,y1i,x2i,y2i,half_size,jump_out;
38        double corr = 0.0;
39        double imax, imin;
40       
41        /* parameter checks */
42        if ((nrhs < 8) || (nlhs != 1)) {
43                mexErrMsgTxt ("Usage: Y = birch_match(im1,im2,max_im2,min_im2,x1,y1,x2,y2,half_size,jump_out)\n\n");
44                return;
45        }
46       
47
48        //not any checking here yet!!!!
49
50        /* reading the parameters */
51        height = mxGetM (prhs [0]);
52        width = mxGetN (prhs [0]);
53        im1 = (double *) mxGetPr (prhs [0]);
54        im2 = (double *) mxGetPr (prhs [1]);
55        max_im2 = (double *) mxGetPr (prhs [2]);
56        min_im2 = (double *) mxGetPr (prhs [3]);
57        x1 = (int)(mxGetScalar(prhs[4]))-1;
58        y1 = (int)(mxGetScalar(prhs[5]))-1;
59        x2 = (int)(mxGetScalar(prhs[6]))-1;
60        y2 = (int)(mxGetScalar(prhs[7]))-1;
61        half_size = (int)(mxGetScalar(prhs[8]));
62        jump_out = (double)(mxGetScalar(prhs[9]));
63
64//      printf("x1 y1 x2 y2 %d %d %d %d\n",x1,y1 ,x2,y2);
65       
66        //out = mxGetScalar(plhs [0]);
67
68        /* require memory for return */
69        plhs [0] = mxCreateDoubleMatrix (1, 1, mxREAL);
70        out = (double *) mxGetPr (plhs [0]);
71       
72
73        // do correlation over a patch
74        for (i = -half_size; i <= half_size; i++)
75        {
76                for (j = -half_size; j <= half_size; j++)
77                {
78                        x1i = x1 + i;
79                        x2i = x2 + i;
80
81                        y1i = y1 + j;
82                        y2i = y2 + j;
83
84                        imax = im1 [y1i * height + x1i]- max_im2 [y2i * height + x2i];
85                        imin = min_im2 [y2i * height + x2i]- im1 [y1i * height + x1i];
86                        imax = max(imax,imin);
87                        corr += max(imax,0.0) * max(imax,0.0);
88
89
90//                      corr += fabs(im1 [y1i * height + x1i]- im2 [y2i * height + x2i]);
91//                      printf("im1 i j x1i y1i %d %d %d %d %lf \n", i,j,x1i,y1i,im1 [x1i * height + y1i]);
92//                      printf("im2 i j x2i y2i %d %d %d %d %lf \n", i,j,x2i,y2i,im2 [x2i * height + y2i]);
93//                      printf("corr i j  %d %d %lf \n", i,j,corr);
94
95                }
96/*              if (corr > jump_out)
97                {
98                        out[0] = corr;
99                        return;
100                }
101*/
102        }
103
104        out[0] = corr;
105
106//      printf("corr \n %lf", corr);
107
108        return;
109}
110
111
112
113                        //      out[0] = im1 [x1 * height + y1]- im2 [x2 * height + y2];
114//      out[0] = im1 [y1 * height + x1]- im2 [y2 * height + x2];
115//      out[0] = im1 [y1 * width + x1]- im2 [y2 * width + x2];
Note: See TracBrowser for help on using the repository browser.