Clarification on conversion between RGB and CIELAB

384 Views Asked by At

I'm working cum clouds of points with PCL. I recently had to convert the color information of the points that are in RGB to Cielab.

I have seen that it is possible to do with OpenCV and then I used the following code:

pcl::PointCloud<pcl::PointXYZLAB>::Ptr convert_rgb_to_lab_opencv(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud) {
pcl::PointCloud <pcl::PointXYZLAB>::Ptr cloud_lab(new pcl::PointCloud <pcl::PointXYZLAB>);

cloud_lab->height = cloud->height;
cloud_lab->width = cloud->width;

for (pcl::PointCloud<pcl::PointXYZRGB>::iterator it = cloud->begin(); it != cloud->end(); it++) {
    // Color conversion
    cv::Mat pixel(1, 1, CV_8UC3, cv::Scalar(it->r, it->g, it->b));
    cv::Mat temp;
    cv::cvtColor(pixel, temp, CV_BGR2Lab);

    pcl::PointXYZLAB point;

    point.x = it->x;
    point.y = it->y;
    point.z = it->z;

    point.L = temp.at<uchar>(0, 0);
    point.a = temp.at<uchar>(0, 1);
    point.b = temp.at<uchar>(0, 2);


    cloud_lab->push_back(point);

}

return cloud_lab;

}

My question is: are the values I got correct? Should not LAB values be decimal and vary with negative numbers?

So I tried to do the conversion "manually" with the code available here. When I visualized the two clouds in the CloudCompare I saw that they produced very similar views, even in the histogram.

Can someone explain to me why?

0

There are 0 best solutions below