区域灰度差变换
程序员文章站
2022-03-11 09:50:35
...
用一个矩形掩模计算像素点的灰度范围
halcon例子:engraved.hdev
原理:
该像素点为中心,所在矩形的最大灰度和最小灰度差。
void gray_range_rect(cv::Mat &src, cv::Mat &dst, int width, int height)
{
int half_w = width / 2;
int half_h = height / 2;
dst = cv::Mat::zeros(src.size(), CV_8UC1);
std::cout << "hello" << std::endl;
for (int i = 0; i < src.cols - width; i++)
{
for (int j = 0; j < src.rows - height; j++)
{
cv::Rect rect = cv::Rect(i, j, width, height);
cv::Mat roi = src(rect);
cv::Point minLoc, maxLoc;
double minVal, maxVal;
cv::minMaxLoc(roi, &minVal, &maxVal, &minLoc, &maxLoc, cv::Mat());
uchar diff = maxVal - minVal;
dst.at<uchar>(j + half_h, i + half_w) = diff;
}
}
}
上一篇: 怎么学html5?
下一篇: Flutter 图片加载