if (isCheck) {
imageMat.copyTo(mRgbaMat);
// READ RGB color image and convert it to Lab
cv::Mat rgbImageMat;
cv::cvtColor(mRgbaMat, rgbImageMat, CV_RGBA2RGB);
cv::Mat bgr_image; rgbImageMat.copyTo(bgr_image);
cv::Mat lab_image;
cv::cvtColor(bgr_image, lab_image, CV_RGB2Lab);
// 保存图片
if(imageCont < 3){
[self saveMat:@"第一步" src:mRgbaMat];
}
// Extract the L channel
std::vectorlab_planes(3);
cv::split(lab_image, lab_planes);
// now we have the L image in lab_planes[0]
// apply the CLAHE algorithm to the L channel
cv::Ptrclahe = cv::createCLAHE();
clahe->setClipLimit(4);
cv::Mat dst;
clahe->apply(lab_planes[0], dst);
// Merge the the color planes back into an Lab image
dst.copyTo(lab_planes[0]);
cv::merge(lab_planes, lab_image);
// convert back to RGB
cv::Mat image_clahe;
//cv::cvtColor(lab_image, image_clahe, CV_Lab2BGR);
cv::cvtColor(lab_image, image_clahe, CV_Lab2RGB);
// display the results (you might also want to see lab_planes[0] before and after).
// 保存图片
if(imageCont < 3) {
[self saveMat:@"original" src:bgr_image];
}
// 保存图片
if(imageCont < 3){
[self saveMat:@"CLAHE" src:image_clahe];
}
self.MyImageView.image = MatToUIImage(mRgbaMat);
}
原图:
效果图: