From 6042c59495ade8f55a7bfedafe8f60c87cd03db5 Mon Sep 17 00:00:00 2001 From: Maria Dimashova Date: Sun, 1 Jul 2012 22:40:25 +0000 Subject: [PATCH] fixed #1764 --- modules/features2d/src/descriptors.cpp | 34 +++++++++++--------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/modules/features2d/src/descriptors.cpp b/modules/features2d/src/descriptors.cpp index 2fb43b7a3..a06fd8fa8 100644 --- a/modules/features2d/src/descriptors.cpp +++ b/modules/features2d/src/descriptors.cpp @@ -134,49 +134,43 @@ static void convertBGRImageToOpponentColorSpace( const Mat& bgrImage, vector rIt = bgrChannels[2].begin(); MatConstIterator_ gIt = bgrChannels[1].begin(); MatIterator_ dstIt = opponentChannels[0].begin(); - float factor = 1.f / sqrt(2.f); for( ; dstIt != opponentChannels[0].end(); ++rIt, ++gIt, ++dstIt ) { - int value = static_cast( static_cast(static_cast(*gIt)-static_cast(*rIt)) * factor ); - if( value < 0 ) value = 0; - if( value > 255 ) value = 255; - (*dstIt) = static_cast(value); + float value = 0.5f * (static_cast(*gIt) - + static_cast(*rIt) + 255); + (*dstIt) = static_cast(value + 0.5f); } } { - // (R + G - 2B)/sqrt(6) + // (R + G - 2B)/sqrt(6), but converted to the destination data type MatConstIterator_ rIt = bgrChannels[2].begin(); MatConstIterator_ gIt = bgrChannels[1].begin(); MatConstIterator_ bIt = bgrChannels[0].begin(); MatIterator_ dstIt = opponentChannels[1].begin(); - float factor = 1.f / sqrt(6.f); for( ; dstIt != opponentChannels[1].end(); ++rIt, ++gIt, ++bIt, ++dstIt ) { - int value = static_cast( static_cast(static_cast(*rIt) + static_cast(*gIt) - 2*static_cast(*bIt)) * - factor ); - if( value < 0 ) value = 0; - if( value > 255 ) value = 255; - (*dstIt) = static_cast(value); + float value = 0.25f * (static_cast(*rIt) + static_cast(*gIt) - + 2*static_cast(*bIt) + 510); + (*dstIt) = static_cast(value + 0.5f); } } { - // (R + G + B)/sqrt(3) + // (R + G + B)/sqrt(3), but converted to the destination data type MatConstIterator_ rIt = bgrChannels[2].begin(); MatConstIterator_ gIt = bgrChannels[1].begin(); MatConstIterator_ bIt = bgrChannels[0].begin(); MatIterator_ dstIt = opponentChannels[2].begin(); - float factor = 1.f / sqrt(3.f); + float factor = 1.f/3.f; for( ; dstIt != opponentChannels[2].end(); ++rIt, ++gIt, ++bIt, ++dstIt ) { - int value = static_cast( static_cast(static_cast(*rIt) + static_cast(*gIt) + static_cast(*bIt)) * - factor ); - if( value < 0 ) value = 0; - if( value > 255 ) value = 255; - (*dstIt) = static_cast(value); + float value = factor * (static_cast(*rIt) + + static_cast(*gIt) + + static_cast(*bIt)); + (*dstIt) = static_cast(value + 0.5f); } } }