目的,找到高对比块,对高对比块进行abf(去紫边)操作,这样不会让非高对比块进行计算,减少运算时间
void ISP_ABF()
{
cv::Mat image = imread("E:/test/color_check.bmp"); // 假设这是你的图像
// 创建一个副本,用于绘制分割线和序号
cv::Mat image_copy = image.clone();
// 设置块的大小
int block_width = image.cols / 10;
int block_height = image.rows / 10;
// 创建一个矩阵来保存每个块的对比度
cv::Mat contrast(image.rows / block_height, image.cols / block_width, CV_32F);
// 将图像分割成多个块,并计算每个块的对比度
for (int i = 0; i < image.rows; i += block_height) {
for (int j = 0; j < image.cols; j += block_width) {
// 获取当前块
cv::Mat block = image(cv::Rect(j, i, block_width, block_height));
// 计算当前块的对比度
cv::Mat laplacian;
cv::Laplacian(block, laplacian, CV_32F);
// 保存当前块的对比度
contrast.at<float>(i / block_height, j / block_width) = cv::mean(cv::abs(laplacian))[0];
// 在副本上绘制分割线和序号
cv::rectangle(image_copy, cv::Rect(j, i, block_width, block_height), cv::Scalar(0, 255, 0), 1);
//cv::putText(image_copy, std::to_string(i / block_height * 25 + j / block_width), cv::Point(j, i), cv::FONT_HERSHEY_SIMPLEX, 1.0, cv::Scalar(0, 0, 255), 2);
cv::putText(image_copy, std::to_string(i / block_height * 10 + j / block_width), cv::Point(j+block_height, i+ block_height), cv::FONT_HERSHEY_SIMPLEX, 1.0, cv::Scalar(0, 0, 255), 2);
}
}
// 显示带有分割线和序号的图像
namedWindow("Image with Grid and Numbers", WINDOW_NORMAL);
cv::imshow("Image with Grid and Numbers", image_copy);
// 找到对比度高的边缘
double minVal, maxVal;
cv::Point minLoc, maxLoc;
cv::minMaxLoc(contrast, &minVal, &maxVal, &minLoc, &maxLoc);
std::cout << "The block with the highest contrast is at (" << maxLoc.x << ", " << maxLoc.y << ")." << std::endl;
for (int i = 0; i < contrast.rows; ++i)
{
for (int j = 0; j < contrast.cols; ++j)
{
float value = contrast.at<float>(i, j);
std::cout << "( " << i << ", " << j << ")" << contrast.at<float>(i, j);
}
cout << std::endl;
}
cv::waitKey(0);
}