I am trying to implement various Matlab functions in opencv. I got output images(in opencv) similar to Matlab. But their pixel values are different. For example output pixels values of 2x2 pixel image:
- Opencv pixel values : [255, 255, 255, 255, 255, 255; 255, 255, 255, 255, 255, 255]
Matlab pixel values : e(:,:,1) = 51.0815 51.0815 51.0815 51.0815 e(:,:,2) = 33.3777 33.3777 33.3777 33.3777 e(:,:,3) = 10.6660 10.6660 10.6660 10.6660 Please help me to resolve my problem. Here is my code also:
for(int i=0;i<irows;i++) {="" for(int="" j="0;j<iCols;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); X1 = 0.436052025fr + 0.385081593fg + 0.143087414f b; Y1 = 0.222491598fr + 0.71688606f g + 0.060621486f *b; Z1 = 0.013929122fr + 0.097097002fg + 0.71418547f *b; xyz.at<vec3b>(i,j)[2]=saturate_cast<uchar>(X1255); xyz.at<vec3b>(i,j)[1]=saturate_cast<uchar>(Y1255); xyz.at<vec3b>(i,j)[0]=saturate_cast<uchar>(Z1255); Vec3b h = xyz.at<vec3b>(i,j); X= h.val[2]; Y= h.val[1]; Z= h.val[0]; xr = X/Xr; yr = Y/Yr; zr = Z/Zr; if ( xr > eps ) fx = (float)pow(xr, 1/3.); else fx = (float) ((k * xr + 16.) / 116.); if ( yr > eps ) fy = (float)pow(yr, 1/3.); else fy = (float) ((k * yr + 16.) / 116.); if ( zr > eps ) fz = (float)pow(zr, 1/3.); else fz = (float) ((k * zr + 16.) / 116); Ls = ( 116 * fy ) - 16; as = 500(fx-fy); bs = 200(fy-fz); Result.at<vec3b>(i,j)[2]=saturate_cast<uchar>((2.55Ls + .5)255); Result.at<vec3b>(i,j)[1]=saturate_cast<uchar>((as + .5)255); Result.at<vec3b>(i,j)[0]=saturate_cast<uchar>((bs + .5)255); }}