diff --git a/modules/features2d/src/descriptors.cpp b/modules/features2d/src/descriptors.cpp index a06fd8fa8b..06efe97913 100644 --- a/modules/features2d/src/descriptors.cpp +++ b/modules/features2d/src/descriptors.cpp @@ -122,57 +122,24 @@ static void convertBGRImageToOpponentColorSpace( const Mat& bgrImage, vector bgrChannels(3); - split( bgrImage, bgrChannels ); - // Prepare opponent color space storage matrices. opponentChannels.resize( 3 ); opponentChannels[0] = cv::Mat(bgrImage.size(), CV_8UC1); // R-G RED-GREEN opponentChannels[1] = cv::Mat(bgrImage.size(), CV_8UC1); // R+G-2B YELLOW-BLUE opponentChannels[2] = cv::Mat(bgrImage.size(), CV_8UC1); // R+G+B - // Calculate the channels of the opponent color space - { - // (R - G)/sqrt(2), but converted to the destination data type - MatConstIterator_ rIt = bgrChannels[2].begin(); - MatConstIterator_ gIt = bgrChannels[1].begin(); - MatIterator_ dstIt = opponentChannels[0].begin(); - for( ; dstIt != opponentChannels[0].end(); ++rIt, ++gIt, ++dstIt ) + for(int y = 0; y < bgrImage.rows; ++y) + for(int x = 0; x < bgrImage.cols; ++x) { - float value = 0.5f * (static_cast(*gIt) - - static_cast(*rIt) + 255); - (*dstIt) = static_cast(value + 0.5f); + Vec3b v = bgrImage.at(y, x); + uchar& b = v[0]; + uchar& g = v[1]; + uchar& r = v[2]; + + opponentChannels[0].at(y, x) = saturate_cast(0.5f * (255 + g - r)); // (R - G)/sqrt(2), but converted to the destination data type + opponentChannels[1].at(y, x) = saturate_cast(0.25f * (510 + r + g - 2*b)); // (R + G - 2B)/sqrt(6), but converted to the destination data type + opponentChannels[2].at(y, x) = saturate_cast(1.f/3.f * (r + g + b)); // (R + G + B)/sqrt(3), but converted to the destination data type } - } - { - // (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(); - for( ; dstIt != opponentChannels[1].end(); ++rIt, ++gIt, ++bIt, ++dstIt ) - { - 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), 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/3.f; - for( ; dstIt != opponentChannels[2].end(); ++rIt, ++gIt, ++bIt, ++dstIt ) - { - float value = factor * (static_cast(*rIt) + - static_cast(*gIt) + - static_cast(*bIt)); - (*dstIt) = static_cast(value + 0.5f); - } - } } struct KP_LessThan