【发布时间】:2018-10-08 09:07:12
【问题描述】:
我想将 bgr mat 转换为实验室垫。然后改变mat中的一些像素。之后,我恢复图像。
int main() {
Mat originalMat = imread("E:\\cworkspace\\Opencv\\Opencv\\test3.jpg");
if (originalMat.empty()) {
cout << "load failed" << endl;
return -1;
}
else {
cout << "load success" << endl << endl;
}
Rect rect = Rect(50, 50, 300, 300);
Mat roi_img = originalMat(rect);
cvtColor(originalMat, originalMat, COLOR_BGR2Lab);
for (int i = 1; i < roi_img.rows; i++) {
for (int j = 1; j < roi_img.cols; j++) {
roi_img.at<Vec3b>(i, j)[0] = 0;
roi_img.at<Vec3b>(i, j)[1] = 0;
roi_img.at<Vec3b>(i, j)[2] = 0;
}
}
cvtColor(originalMat, originalMat, COLOR_Lab2BGR);
imshow("originalMat", originalMat);
waitKey();
return 0;
}
这是我的简化代码。最终投资回报率变成了蓝色。根据我的理解。它应该是黑色的。
【问题讨论】:
-
当使用 8 位无符号值时,(0,0,0) 在 Lab 中不是黑色的。参见the docs --
a和b偏移 128。