I want to cvt bgr mat to lab mat. Then change some pixels in mat. After that, I restore image.
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;
}
This is my simplified code.Eventually the ROI was changed to blue.From my understanding.It should be black.
a
andb
are offset by 128. – Dan Mašek