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

问题描述 投票:0回答:1

opencv 文档我发现 Lab* 颜色空间对于每个变量都有有限的值,如下所示:

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

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

例如,在像素 (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;
   }
c++ opencv lab-color-space
1个回答
1
投票

这里是 cvtColor 的参考,在 RGB <-> CIE L*a*b* 部分它说:

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

© www.soinside.com 2019 - 2024. All rights reserved.