void DirectSegmentsBase::coloriage( double x_1, double y_1, double x_2, double y_2, image::Image& inasegment, int _value) { double xStep = (x_2 - x_1); double yStep = (y_2 - y_1); double norm_steps = sqrt( xStep * xStep + yStep * yStep ); xStep /= norm_steps; yStep /= norm_steps; int max_coloriage = (int)norm_steps +1; for( int k = 0; k < max_coloriage; ++k ) { int x = (int)( x_1 + k * xStep ); int y = (int)( y_1 + k * yStep ); for( int j = -1; j <= 1; ++j) { for( int i = -1; i <= 1; ++i) { if( check( x + i, inasegment.width() - 1 ) and check( y + j, inasegment.height() - 1 ) ) { inasegment.setPixelValue<int>( _value, x+i, y+j, 0 ); } } } } #if 0 double xStep = (x_2 - x_1); double yStep = (y_2 - y_1); double norm_steps = sqrt( xStep * xStep + yStep * yStep ); xStep /= norm_steps; yStep /= norm_steps; int max_coloriage = (int)norm_steps +1; int p_x = x_1; int p_y = y_1; if( check( p_x, inasegment.width() - 1 ) and check( p_y, inasegment.height() - 1 ) ) { inasegment.setPixelValue<int>( _value, p_x, p_y, 0 ); } for( int k = -1; k <= max_coloriage; ++k ) { int x = (int)( x_1 + k * xStep ); int y = (int)( y_1 + k * yStep ); if( check( p_x, inasegment.width() - 1 ) and check( y, inasegment.height() - 1 ) ) { inasegment.setPixelValue<int>( _value, p_x, y, 0 ); } if( check( x, inasegment.width() - 1 ) ) { if( check( p_y, inasegment.height() - 1 ) ) { inasegment.setPixelValue<int>( _value, x, p_y, 0 ); } if( check( y, inasegment.height() - 1 ) ) { inasegment.setPixelValue<int>( _value, x, y, 0 ); } } p_x = x; p_y = y; } #endif }
void GradientsDescriptor::fillHisto( const image::Image& _dx, const image::Image& _dy, double* _histo, const jblas::vec2& _startPoint, const jblas::vec2& _direction, double _lineAngle, int _length, double _coef ) { jblas::vec2 currentPoint = _startPoint + 3.0 * _direction; double lastNorm = DBL_MAX; for(int i = 0; i < _length; ++i) // while(true) { int ix = int(currentPoint(0)); int iy = int(currentPoint(1)); if( not check(ix, _dx.width() - 1) or not check(iy, _dx.height() - 1) ) return; int dx = _dx.getPixelValue<short>( ix, iy, 0 ); int dy = _dy.getPixelValue<short>( ix, iy, 0 ); // double dx = _dx.getSubPixelValue<short>( ix, iy, 0, JfrImage_INTERP_CUBIC ); // double dy = _dy.getSubPixelValue<short>( ix, iy, 0, JfrImage_INTERP_CUBIC ); double norm = sqrt( dx * dx + dy * dy ); // if( norm > lastNorm) return ; double angle = atan2(dy, dx); // double diff = cos( angle - _lineAngle); double correctedAngle = ( angle - _lineAngle); // int idx = int( (m_count) * ( 1.0 + diff) * 0.5); // if( idx >= m_count ) idx = m_count - 1; // if( idx != 0 and idx != (m_count - 1 ) ) for(int j = 0; j < m_count; ++j ) { // double lnorm = norm * ( 1.0 - fabs( fpow( -1.0 + 2.0 * j / (m_count-1) - diff ), 2.0) ); // double lnorm = norm * exp( -pow( -1.0 + 2.0 * j / (m_count-1) - diff, 2.0) ); // JFR_DEBUG( j << " " << exp( -pow2( cos( M_PI * j / (m_count-1) - 0.5 * correctedAngle ) ) ) ); double lnorm = norm * _coef * exp( -pow2( cos( M_PI * j / (m_count-1) - 0.5 * correctedAngle ) ) ); _histo[ j ] += lnorm; } lastNorm = norm; currentPoint += _direction; } }