Implementation of lab2xyz in opencv using c++

asked 2015-09-06 13:44:43 -0500

Tess gravatar image

updated 2015-09-06 13:49:43 -0500

I am trying to implement Matlab function lab2xyz in opencv using c++, with whitepoint D50.But I got only Black image as output. Here is my code , please help me to resolve my problem.

`

 float x=0.964221f,y=1.0f,z=0.825211f;

for(int i=0;i<rn;i++)
{
 for(int j=0;j<cn;j++)
   {
     Vec3b intensity = image.at<Vec3b>(i,j);

     L= intensity.val[2];
     a= intensity.val[1];
     b= intensity.val[0];
     fy =(( L + 16. )/116.);
     fx=((a / 500.)+ fy);
     fz=(fy- (b/ 200.));
     if( pow(fx,3.) > 0.008856 ) 
       X =  pow(fx,3.);
     else
       X = ( fx - 16. / 116. ) / 7.787;
     if( pow(fy,3.) > 0.008856 ) 
         Y=  pow(fy,3.);
      else
         Y = ( fy- 16. / 116. ) / 7.787;
      if( pow(fz,3.) > 0.008856 ) 
        Z =  pow(fz,3.);
      else
       Z= ( fz- 16. / 116. ) / 7.787;
       X = X * x;
       Y = Y * y;
       Z = Z * z;
     Result.at<Vec3b>(i,j)[2]=saturate_cast<uchar>(X);
     Result.at<Vec3b>(i,j)[1]=saturate_cast<uchar>(Y); 
     Result.at<Vec3b>(i,j)[0]=saturate_cast<uchar>(Z); 
  }  }`
edit retag flag offensive close merge delete

Comments

How many exercises have to resolve as this one?

LBerger gravatar imageLBerger ( 2015-09-06 13:57:33 -0500 )edit

@LBerger: nearly 15

Tess gravatar imageTess ( 2015-09-06 14:35:41 -0500 )edit
1

I don't think that's a good way to work (sorry for my bad english). All questions you have asked are quite similar. May be you should use this take some values in first and second color space and write a small program without opencv to find good function. When you've got it write your programm with opencv.

That's only my own opinion

PS I think that you have already check what's possible in opencv

LBerger gravatar imageLBerger ( 2015-09-06 14:59:11 -0500 )edit