读取L * a * b颜色空间图像的像素

时间:2017-02-25 15:10:32

标签: c++ opencv colors space lab

opencv documentation我发现L a b *颜色空间对每个变量的值有限,如下所示:

   0 < L < 100
-127 < a < 127 
-127 < b < 127

我编写了一个代码,用于读取BGR类型的图像并将其转换为L a b *颜色空间。当我显示L的值时,a和b i发现值超出范围(全部)

例如,在像素(y,x)中,b的值为150,但是从opencv 2.4.13文档b必须介于-127和127之间。 代码如下:

   #include <opencv2/core/core.hpp>
   #include <opencv2/highgui/highgui.hpp>
   #include "opencv2/imgproc/imgproc.hpp"
   #include <iostream>

   using namespace cv;
   using namespace std;


   int main(int argc, char** argv){

    Mat input, Lab_img;

    input = imread("E:\\Walid\\Images\\b2.jpg");


    cvtColor(input, Lab_img, CV_BGR2Lab);
    namedWindow("ORIGINAL", WINDOW_AUTOSIZE);
    namedWindow("Lab", WINDOW_AUTOSIZE);



    for (int y = 0; y < Lab_img.rows; y++)
    {
        for (int x = 0; x < Lab_img.cols; x++)
        {
            Vec3b intensity = Lab_img.at<Vec3b>(y, x);
            double L = intensity.val[0];
            double a = intensity.val[1];
            double b = intensity.val[2];
            cout << b << std::endl;
        }
    }


    imshow("ORIGINAL", input);
    imshow("Lab", Lab_img);

    waitKey(0);
    return 0;
   }

1 个答案:

答案 0 :(得分:0)

以下是cvtColor的参考。在RGB&lt; - &gt;部分中CIE L * a * b *它说:

  

这输出0 <= L <= 100,-127 <= a <= 127,-127 <= b <= 127。的的   然后将值转换为目标数据类型:对于8位   图像L = L * 255/100,a = a + 128,b = b + 128。

相关问题