Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Implementation of Matlab function rgb2lab in opencv using c++

I am trying to implement rgb2ntsc colorspace conversion in OpenCV using C++. for(int i=0;i<rn;i++) {="" for(int="" j="0;j&lt;cn;j++)" {="" vec3b="" intensity="image.at&lt;Vec3b">(i,j); R = intensity.val[2]; G = intensity.val[1]; B = intensity.val[0]; Y = 0.299R+0.587G+0.114B; I = 0.596R-0.274G-0.322B; Q = 0.211R-0.523G+0.312*B; Result.at<vec3b>(i,j)[0] = (float)Y; Result.at<vec3b>(i,j)[1] = (float)I; Result.at<vec3b>(i,j)[2] = (float)Q; } }

I have done this for the implementation of rgb2ntsc. But my output image is not similar to the output of Matlab's rgb2ntsc function. Here are my input image, output image and matlab output image. Can I do any additional operation? input image My output image Matlab output image

click to hide/show revision 2
No.2 Revision

updated 2015-09-04 05:02:08 -0600

berak gravatar image

Implementation of Matlab function rgb2lab in opencv using c++

I am trying to implement rgb2ntsc colorspace conversion in OpenCV using C++. C++.

for(int i=0;i<rn;i++) {="" for(int="" j="0;j&lt;cn;j++)" {="" vec3b="" intensity="image.at&lt;Vec3b">(i,j);
{
    for(int j=0;j<cn;j++) {
        Vec3b intensity = image.at<Vec3b>(i,j);
        R = intensity.val[2];
        G = intensity.val[1];
        B = intensity.val[0];
        Y = 0.299R+0.587G+0.114B;
        I = 0.596R-0.274G-0.322B;
0.299*R+0.587*G+0.114*B;
        I = 0.596*R-0.274*G-0.322*B;
        Q = 0.211R-0.523G+0.312*B;
        Result.at<vec3b>(i,j)[0] 0.211*R-0.523*G+0.312*B;
        Result.at<Vec3b>(i,j)[0] = (float)Y;
        Result.at<vec3b>(i,j)[1] Result.at<Vec3b>(i,j)[1] = (float)I;
        Result.at<vec3b>(i,j)[2] Result.at<Vec3b>(i,j)[2] = (float)Q;
    }
}

}

I have done this for the implementation of rgb2ntsc. But my output image is not similar to the output of Matlab's rgb2ntsc function. Here are my input image, output image and matlab output image. Can I do any additional operation? operation?

input image My output image Matlab output image

Implementation of Matlab function rgb2lab rgb2ntsc in opencv using c++

I am trying to implement rgb2ntsc colorspace conversion in OpenCV using C++.

for(int i=0;i<rn;i++) {
    for(int j=0;j<cn;j++) {
        Vec3b intensity = image.at<Vec3b>(i,j);
        R = intensity.val[2];
        G = intensity.val[1];
        B = intensity.val[0];
        Y = 0.299*R+0.587*G+0.114*B;
        I = 0.596*R-0.274*G-0.322*B;
        Q = 0.211*R-0.523*G+0.312*B;
        Result.at<Vec3b>(i,j)[0] = (float)Y;
        Result.at<Vec3b>(i,j)[1] = (float)I;
        Result.at<Vec3b>(i,j)[2] = (float)Q;
    }
}

I have done this for the implementation of rgb2ntsc. But my output image is not similar to the output of Matlab's rgb2ntsc function. Here are my input image, output image and matlab output image. Can I do any additional operation?

input image My output image Matlab output image