Example #1
0
	BPPottsPotential(const float* features1, const float* features2, int D, int N1, int N2, float w, bool per_pixel_normalization=true) :N1_(N1), N2_(N2), w_(w) {
		float * features = new float[ (N1_+N2_)*D ];
		memset( features, 0, (N1_+N2_)*D*sizeof(float) );
		memcpy( features      , features1, N1_*D*sizeof(float) );
		memcpy( features+N1_*D, features2, N2_*D*sizeof(float) );
		lattice_.init( features, D, N1_+N2_ );
		delete [] features;
		
		norm_ = allocate( N2_ );
		float * tmp = allocate( N1_ );
		for( int i=0; i<N1_; i++ )
			tmp[i] = 1;
		// Compute the normalization factor
		lattice_.compute( norm_, tmp, 1, 0, N1_, N1_, N2_ );
		if( per_pixel_normalization ){
			// use a per pixel normalization
			for( int i=0; i<N2_; i++ )
				norm_[i] = 1.f / (norm_[i]+1e-20f);
		}
		else{
			float mean_norm = 0;
			for( int i=0; i<N2_; i++ )
				mean_norm += norm_[i];
			mean_norm = N2_ / mean_norm;
			// use a per pixel normalization
			for( int i=0; i<N2_; i++ )
				norm_[i] = mean_norm;
		}
		deallocate( tmp );
	}
Example #2
0
	PottsPotential(const float* features, int D, int N, float w, bool per_pixel_normalization=true) :N_(N), w_(w) {
		lattice_.init( features, D, N );
		norm_ = allocate( N );
		for ( int i=0; i<N; i++ )
			norm_[i] = 1;
		// Compute the normalization factor
		lattice_.compute( norm_, norm_, 1 );
		if ( per_pixel_normalization ) {
			// use a per pixel normalization
			for ( int i=0; i<N; i++ )
				norm_[i] = 1.f / (norm_[i]+1e-20f);
		}
		else {
			float mean_norm = 0;
			for ( int i=0; i<N; i++ )
				mean_norm += norm_[i];
			mean_norm = N / mean_norm;
			// use a per pixel normalization
			for ( int i=0; i<N; i++ )
				norm_[i] = mean_norm;
		}
	}
Example #3
0
	void initLattice( const MatrixXf & f ) {
		const int N = f.cols();
		lattice_.init( f );
		
		norm_ = lattice_.compute( VectorXf::Ones( N ).transpose() ).transpose();
		
		if ( ntype_ == NO_NORMALIZATION ) {
			float mean_norm = 0;
			for ( int i=0; i<N; i++ )
				mean_norm += norm_[i];
			mean_norm = N / mean_norm;
			for ( int i=0; i<N; i++ )
				norm_[i] = mean_norm;
		}
		else if ( ntype_ == NORMALIZE_SYMMETRIC ) {
			for ( int i=0; i<N; i++ )
				norm_[i] = 1.0 / sqrt(norm_[i]+1e-20);
		}
		else {
			for ( int i=0; i<N; i++ )
				norm_[i] = 1.0 / (norm_[i]+1e-20);
		}
	}