www.pudn.com > match-v3.3.src.rar > corr.cpp


/* corr.cpp */ 
/* Vladimir Kolmogorov (vnk@cs.cornell.edu), 2001-2003. */ 
 
#include  
#include "match.h" 
 
/************************************************************/ 
/************************************************************/ 
/************************************************************/ 
 
inline int Match::CORR_data_penalty(Coord l, Coord r) 
{ 
	return (this->*data_penalty_func)(l, r); 
} 
 
/************************************************************/ 
/************************************************************/ 
/************************************************************/ 
 
#define DEFAULT_V 100 
 
/* 
  compute correlation values for disparity d 
  using 1D correlation window (along horizontal lines) 
*/ 
void Match::CORR_hor(Coord d, LongImage v_hor) 
{ 
	Coord p, pd; 
	int w_size, w2_size; 
	int x_start, x_finish; 
	int v, v_sum; 
 
	w_size = params.corr_size; 
	w2_size = 2*w_size + 1; 
 
	for (p.y=0; p.y=im_size.y) 
		{ 
			for (p.x=0; p.x 0) 
		{ 
			x_start = 0; 
			x_finish = im_size.x - 1 - d.x; 
			if (x_start > x_finish) x_finish = x_start - 1; 
		} 
		else 
		{ 
			x_start = 0 - d.x; 
			x_finish = im_size.x - 1; 
			if (x_start > x_finish) x_start = x_finish + 1; 
		} 
		/* now we can access L(p) and R(p+d) if x_start<=p.x<=x_finish */ 
 
		v_sum = w2_size*DEFAULT_V; 
		for (p.x=x_start; p.x 0) 
		{ 
			v_sum = imRef(v_hor, x_finish, p.y); 
			for (p.x=x_finish+1; p.x=0 && p.x-w_size-1+d.x=0; p.x--) 
			{ 
				if (p.x+w_size+1=0) 
				{ 
					v = CORR_data_penalty(Coord(p.x+w_size+1, p.y), Coord(p.x+w_size+1+d.x, pd.y)); 
					v_sum -= v; 
				} 
				else v_sum -= DEFAULT_V; 
				v_sum += DEFAULT_V; 
				IMREF(v_hor, p) = v_sum; 
			} 
		} 
	} 
} 
 
/************************************************************/ 
/************************************************************/ 
/************************************************************/ 
 
/* 
  compute correlation values 
  using full 2D correlation window 
*/ 
void Match::CORR_full(LongImage v_hor, LongImage v_full) 
{ 
	Coord p; 
	int w_size, w2_size; 
	int v, v_sum; 
 
	w_size = params.corr_size; 
	w2_size = 2*w_size + 1; 
 
	for (p.x=0; p.x=im_base && q<=im_max && qd>=im_base && qd<=im_max) 
					{ 
						v = CORR_value(q, qd); 
						v_sum += v; 
					} 
					else v_sum += DEFAULT_V; 
				} 
				if (v_sum != IMREF(v_full, p)) { fprintf(stderr, "Error in CORR!\n"); exit(1); } 
			} 
		} 
#endif 
	} 
 
	/* finding disparity with minimum correlation value */ 
	for (p.y=0; p.y