cvtColor() BGR2YUV and YUV2BGR confused in B and R channels (Bug #2562)


Added by Daniil Osokin over 12 years ago. Updated about 12 years ago.


Status:Cancelled Start date:2012-11-21
Priority:Normal Due date:
Assignee:Daniil Osokin % Done:

0%

Category:imgproc, video
Target version:2.4.4
Affected version:2.4.3 Operating System:
Difficulty: HW Platform:
Pull request:

Description

It seems, that B and R channels don't swapped, when needed.
In cvtColor(src, dst, CV_BGR2YUV) (modules/imgproc/src/color.cpp, line 3384) we have:

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

Here we should swap B and R channels in case of BGR source, because next we invoke RGB2YCrCb conversion. But the second code - CV_RGB2YUV looks suspicious, this should be changed like:
bidx = code == CV_BGR2YCrCb || code == CV_BGR2YUV ? 0 : 2;

The same modification should be done with CV_YUV2BGR mode (modules/imgproc/src/color.cpp, line 3413):
bidx = code == CV_YCrCb2BGR || code == CV_YUV2RGB ? 0 : 2;

I'm on master.


Associated revisions

Revision d1710a85
Added by Andrey Pavlenko almost 11 years ago

Merge pull request #2562 from akarsakov:gftt_fix

History

Updated by Daniil Osokin over 12 years ago

  • Description changed from It seems, that B and R channels don't swapped, when needed. In cvtColor(s... to It seems, that B and R channels don't swapped, when needed. In cvtColor(s... More

Updated by Vadim Pisarevsky about 12 years ago

  • Affected version set to 2.4.3
  • Target version deleted ()

Updated by Vadim Pisarevsky about 12 years ago

  • Assignee deleted (Vadim Pisarevsky)

Updated by Daniil Osokin about 12 years ago

  • Assignee set to Daniil Osokin

Updated by Daniil Osokin about 12 years ago

Sorry, this statement is wrong. Here code to reproduce proposed behaviour, but it produces right image:

    Mat bgrImage = imread("path_to_rgb_image", 1);
    Mat rgbImage;
    cvtColor(bgrImage, rgbImage, CV_BGR2RGB);
    Mat yuvImage;
    cvtColor(rgbImage, yuvImage, CV_RGB2YUV);
    // downsampling yuvImage for CV_YUV2BGR_IYUV conversion
    vector<Mat> yuvPlanes;
    split(yuvImage, yuvPlanes);
    Size halfSize = Size(yuvImage.cols/2, yuvImage.rows/2);
    resize(yuvPlanes[1], yuvPlanes[1], halfSize, 0, 0, INTER_AREA);
    resize(yuvPlanes[2], yuvPlanes[2], halfSize, 0, 0, INTER_AREA);
    // create YUV420p source
    Mat yuv420pImage(yuvImage.rows + yuvImage.rows/2, yuvImage.cols, CV_8UC1);
    yuvPlanes[0].copyTo(Mat(yuvImage.rows, yuvImage.cols, CV_8UC1, yuv420pImage.data));
    yuvPlanes[1].copyTo(Mat(yuvImage.rows/2, yuvImage.cols/2, CV_8UC1, yuv420pImage.data + yuvPlanes[0].total()));
    yuvPlanes[2].copyTo(Mat(yuvImage.rows/2, yuvImage.cols/2, CV_8UC1, yuv420pImage.data + yuvPlanes[0].total() + yuvPlanes[1].total()));

    Mat bgrImageFromYUV420p;
    cvtColor(yuv420pImage, bgrImageFromYUV420p, CV_YUV2BGR_IYUV);
    imshow("Output image", bgrImageFromYUV420p);
    waitKey(0);

  • Status changed from Open to Cancelled

Updated by Kirill Kornyakov about 12 years ago

  • Target version set to 2.4.4

Also available in: Atom PDF