将OpenCV BGR 8位图像转换为CIE L * a * b * [英] Converting an OpenCV BGR 8-bit Image to CIE L*a*b*
问题描述
我试图将表示具有8位深度的 RGB 图像的给定 Mat
转换为 Lab 文档中提供的函数:
I am trying to convert a given Mat
representing an RGB image with 8-bit depth to Lab using the function provided in the documentation:
cvtColor(source, destination, <conversion code>);
我尝试过以下转换代码:
I have tried the following conversion codes:
CV_RGB2Lab
CV_BGR2Lab
CV_LBGR2Lab
我每次都收到奇怪的结果,对于一些样品,L值大于100,字面上<107,125,130>。
I have received bizarre results each time around, with an "L" value of greater than 100 for some samples, literally <107, 125, 130>.
I我也使用Photoshop检查结果 - 但考虑到107超出了接受范围0≤L≤100,我不能理解我的错误是什么。
I am also using Photoshop to check the results - but given that 107 is beyond the accepted range of 0 ≤ L ≤ 100, I can not comprehend what my error is.
更新:
我将在这里发布我的整体结果:
给定由8位BGR表示的图像(Mat),图像可以通过以下转换:
Update: I'll post my overall results here: Given an image (Mat) represented by 8-bit BGR, the image can be converted by the following:
cvtColor(source, destination, CV_BGR2Lab);
然后可以通过以下方式访问像素值:
The pixel values can then be accessed in the following manner:
int step = destination.step;
int channels = destination.channels();
for (int i = 0; i < destination.rows(); i++) {
for (int j = 0; j < destination.cols(); j++) {
Point3_<uchar> pixelData;
//L*: 0-255 (elsewhere is represented by 0 to 100)
pixelData.x = destination.data[step*i + channels*j + 0];
//a*: 0-255 (elsewhere is represented by -127 to 127)
pixelData.y = destination.data[step*i + channels*j + 1];
//b*: 0-255 (elsewhere is represented by -127 to 127)
pixelData.z = destination.data[step*i + channels*j + 2];
}
}
推荐答案
因为 L 值在OpenCV中的范围 [0..255] 。您可以简单地将此值缩放到所需的间隔( [0..100] )。
That's because L value is in range [0..255] in OpenCV. You can simply scale this value to needed interval ([0..100] in your case).
这篇关于将OpenCV BGR 8位图像转换为CIE L * a * b *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!