0

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?

  • You can always check the [documentation of OpenCV on this](https://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html#cvtcolor). Basically, it depends on what you need, and what you pass as source. If it is an CV_U8C3 (normal BGR image) it will return one like that one, with the range shifted to fit the type (look the documentation). If you pass a CV_32FC3 image you will get it as is, with float values and negative numbers, but the source image should be scale to 0-1 scale instead of 0-255 – api55 May 28 '18 at 19:18
  • 2
    But shouldn't the Scalar been defined as `cv::Scalar(it->b, it->g, it->r)` ? – Mark Loyman May 29 '18 at 04:53
  • I have the same question. – Tiago A. Silva May 29 '18 at 16:10

0 Answers0