pull/2/head
Maria Dimashova 13 years ago
parent 31395b0759
commit 6042c59495
  1. 34
      modules/features2d/src/descriptors.cpp

@ -134,49 +134,43 @@ static void convertBGRImageToOpponentColorSpace( const Mat& bgrImage, vector<Mat
// Calculate the channels of the opponent color space
{
// (R - G) / sqrt(2)
// (R - G)/sqrt(2), but converted to the destination data type
MatConstIterator_<signed char> rIt = bgrChannels[2].begin<signed char>();
MatConstIterator_<signed char> gIt = bgrChannels[1].begin<signed char>();
MatIterator_<unsigned char> dstIt = opponentChannels[0].begin<unsigned char>();
float factor = 1.f / sqrt(2.f);
for( ; dstIt != opponentChannels[0].end<unsigned char>(); ++rIt, ++gIt, ++dstIt )
{
int value = static_cast<int>( static_cast<float>(static_cast<int>(*gIt)-static_cast<int>(*rIt)) * factor );
if( value < 0 ) value = 0;
if( value > 255 ) value = 255;
(*dstIt) = static_cast<unsigned char>(value);
float value = 0.5f * (static_cast<int>(*gIt) -
static_cast<int>(*rIt) + 255);
(*dstIt) = static_cast<unsigned char>(value + 0.5f);
}
}
{
// (R + G - 2B)/sqrt(6)
// (R + G - 2B)/sqrt(6), but converted to the destination data type
MatConstIterator_<signed char> rIt = bgrChannels[2].begin<signed char>();
MatConstIterator_<signed char> gIt = bgrChannels[1].begin<signed char>();
MatConstIterator_<signed char> bIt = bgrChannels[0].begin<signed char>();
MatIterator_<unsigned char> dstIt = opponentChannels[1].begin<unsigned char>();
float factor = 1.f / sqrt(6.f);
for( ; dstIt != opponentChannels[1].end<unsigned char>(); ++rIt, ++gIt, ++bIt, ++dstIt )
{
int value = static_cast<int>( static_cast<float>(static_cast<int>(*rIt) + static_cast<int>(*gIt) - 2*static_cast<int>(*bIt)) *
factor );
if( value < 0 ) value = 0;
if( value > 255 ) value = 255;
(*dstIt) = static_cast<unsigned char>(value);
float value = 0.25f * (static_cast<int>(*rIt) + static_cast<int>(*gIt) -
2*static_cast<int>(*bIt) + 510);
(*dstIt) = static_cast<unsigned char>(value + 0.5f);
}
}
{
// (R + G + B)/sqrt(3)
// (R + G + B)/sqrt(3), but converted to the destination data type
MatConstIterator_<signed char> rIt = bgrChannels[2].begin<signed char>();
MatConstIterator_<signed char> gIt = bgrChannels[1].begin<signed char>();
MatConstIterator_<signed char> bIt = bgrChannels[0].begin<signed char>();
MatIterator_<unsigned char> dstIt = opponentChannels[2].begin<unsigned char>();
float factor = 1.f / sqrt(3.f);
float factor = 1.f/3.f;
for( ; dstIt != opponentChannels[2].end<unsigned char>(); ++rIt, ++gIt, ++bIt, ++dstIt )
{
int value = static_cast<int>( static_cast<float>(static_cast<int>(*rIt) + static_cast<int>(*gIt) + static_cast<int>(*bIt)) *
factor );
if( value < 0 ) value = 0;
if( value > 255 ) value = 255;
(*dstIt) = static_cast<unsigned char>(value);
float value = factor * (static_cast<int>(*rIt) +
static_cast<int>(*gIt) +
static_cast<int>(*bIt));
(*dstIt) = static_cast<unsigned char>(value + 0.5f);
}
}
}

Loading…
Cancel
Save