Error in CvtColor code, wrong channel identified as blue (Bugfix #3121)


Added by Clark Taylor over 11 years ago. Updated over 11 years ago.


Status:Done Start date:2013-06-28
Priority:Normal Due date:
Assignee:Dmitry Retinskiy % Done:

100%

Category:imgproc, video
Target version:2.4.7
Affected version:2.4.6 (latest release) Operating System:Any
Difficulty:Easy HW Platform:Any
Pull request:https://github.com/Itseez/opencv/pull/1196

Description

The following code is found on line 2520 of color.cpp

bidx = code CV_BGR2YCrCb || code CV_RGB2YUV ? 0 : 2;

It should read

bidx = code CV_BGR2YCrCb || code CV_BGR2YUV ? 0 : 2;

Or simply, the bidx should be 0 only if the input is in BGR, not RGB format.


Associated revisions

Revision d1fe0b4b
Added by Dmitry Retinskiy over 11 years ago

bugfix #3121: updated sanity data in imgproc for BGR2YUV, YUV2BGR conversions

Revision 2fb2ac88
Added by Peng Xiao over 11 years ago

Apply bugfix #3121 for OCL.

Revision 70679b49
Added by Vadim Pisarevsky over 10 years ago

Merge pull request #3121 from akarsakov:ocl_dft_opt

History

Updated by Kirill Kornyakov over 11 years ago

It would be great if somebody could work on a pull request...

  • Assignee deleted (Vadim Pisarevsky)
  • Affected version changed from 2.4.5 (latest release) to 2.4.6 (latest release)
  • Target version changed from 2.4.6 to Next Hackathon
  • Status changed from New to Open

Updated by Nikita Manovich over 11 years ago

  • Pull request set to https://github.com/Itseez/opencv/pull/1120

Updated by Nikita Manovich over 11 years ago

The example works fine with the current version of OpenCV. Probably OpenCV doesn't contain the bug but code isn't very clear. Need to investigate the problem deeply.

#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/types_c.h>
#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        std::cout << "Usage: " << argv[0] << " <image>" << std::endl;
        return -1;
    }

    std::string name = argv[1];
    cv::Mat bgr = cv::imread(name), rgb, yuv;

    cv::cvtColor(bgr, yuv, CV_BGR2YUV);

    cv::cvtColor(yuv, rgb, CV_YUV2RGB);
    cv::cvtColor(rgb, bgr, CV_RGB2BGR);

    cv::namedWindow("bgr");
    cv::imshow("bgr", bgr);

    cv::waitKey();
    return 0;
}
  • Pull request deleted (https://github.com/Itseez/opencv/pull/1120)

Updated by Dmitry Retinskiy over 11 years ago

This is probably because fix needs to be applied in both conversion cases:

3460: bidx = code CV_BGR2YCrCb || code CV_RGB2YUV ? 0 : 2;

and

3489: bidx = code CV_YCrCb2BGR || code CV_YUV2RGB ? 0 : 2;

Updated by Dmitry Retinskiy over 11 years ago

  • Assignee set to Dmitry Retinskiy
  • Pull request set to https://github.com/Itseez/opencv/pull/1196

Updated by Dmitry Retinskiy over 11 years ago

It looks like sanity data for the regression tests needs to be updated too.

Updated by Dmitry Retinskiy over 11 years ago

Pull request is under review.

Updated by Dmitry Retinskiy over 11 years ago

  • % Done changed from 0 to 100
  • Status changed from Open to Done
  • HW Platform changed from x86 to Any
  • Target version changed from Next Hackathon to 2.4.7

Also available in: Atom PDF