Implementation of rgb2xyz in opencv using c++
I am trying to implement matlab rgb2xyz function in opencv using c++. I used cvtColor function for implementation.
But my output image is not similar to Matlab output image.Should I use any other function or operations on image ?Here is my input image ,matlab output image and my output image.image.
Hai...
Edit: I got 1 more code for the implementation of rgb2xyz.But it gave me black output image. Here is the code.
for(int i=0;i<rn;i++) {="" for(int="" j="0;j<cn;j++)" {="" vec3b="" intensity="image.at<Vec3b">(i,j);
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];
r = R/255.f; //R 0..1
g = G/255.f; //G 0..1
b = B/255.f; //B 0..1
if (r <= 0.04045)
r = r/12;
else
r = (float)pow((r+0.055)/1.055,2.4);
if (g <= 0.04045)
g = g/12;
else
g = (float)pow((g+0.055)/1.055,2.4);
if (b <= 0.04045)
b = b/12;
else
b = (float)pow((b+0.055)/1.055,2.4);
X = 0.436052025fr + 0.385081593fg 0.436052025f*r + 0.385081593f*g + 0.143087414f b;
*b;
Y = 0.222491598fr 0.222491598f*r + 0.71688606f g *g + 0.060621486f *b;
Z = 0.013929122fr 0.013929122f*r + 0.097097002f*g + 0.71418547f *b;
Result.at<vec3b>(i,j)[0]=(float)X;
Result.at<vec3b>(i,j)[1]=(float)Y;
Result.at<vec3b>(i,j)[2]=(float)Z; Result.at<Vec3b>(i,j)[0]=(float)X;
Result.at<Vec3b>(i,j)[1]=(float)Y;
Result.at<Vec3b>(i,j)[2]=(float)Z;
}
}}