【发布时间】:2012-07-08 08:24:03
【问题描述】:
我正在尝试使用文档中提供的函数将代表具有 8 位深度的 RGB 图像的给定 Mat 转换为 Lab:
cvtColor(source, destination, <conversion code>);
我尝试了以下转换代码:
CV_RGB2Lab
CV_BGR2Lab
CV_LBGR2Lab
我每次都收到奇怪的结果,某些样本的“L”值大于 100,字面意思是 。
我也在使用 Photoshop 来检查结果 - 但鉴于 107 超出了 0 ≤ L ≤ 100 的可接受范围,我无法理解我的错误是什么。
更新: 我将在这里发布我的总体结果: 给定一张由 8 位 BGR 表示的图像(Mat),图像可以通过以下方式进行转换:
cvtColor(source, destination, CV_BGR2Lab);
然后可以通过以下方式访问像素值:
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];
}
}
【问题讨论】:
-
此外,在不知道颜色配置文件的情况下,您无法以可靠的结果进行 RGB 到 Lab 转换。 RGB 不是独立的色彩空间,Lab 是。