c++ - 更有效的图像窗口/级别调整方式?C++
问题描述
我正在为我的图像处理课程编写这个程序,我需要创建一个大小为 30 的窗口(我假设为 30 像素,因为我的导师没有指定),我在其中对所有像素执行线性灰度转换窗框内。我编写了以下代码:
// create a window 30 image to modify
Mat window30(relax.size(), relax.type());
// traverse through the whole image with our 5x6 window and linearly transform the pixel values in the image
for (int i = 0; i < window30.rows; i=i+5)
{
for (int j = 0; j < window30.cols; j=j+6)
{
for (int n = 0; n < 5; n++)
{
for (int m = 0; m < 6; m++)
{
// if pixel value is below 50 set that value to 0
if (window30.at<uchar>(i+n,j+m) < 50)
{
window30.at<uchar>(i + n, j + m) = 0;
}
// if between 50 and 169 transform it to the value multiplied by 1.08875
else if (window30.at<uchar>(i + n, j + m) >= 50 and window30.at<int>(i + n, j + m) < 170)
{
window30.at<uchar>(i + n, j + m) = 1.08875 * window30.at<int>(i + n, j + m);
}
// else just set value to 255
else
{
window30.at<uchar>(i + n, j + m) = 255;
}
}
}
}
}
imshow("window30", window30);
waitKey(0);
这是我第一次使用 OpenCV 和 C++ 处理计算机视觉。我知道我的代码是垃圾,但我整天都被这个问题困扰,并且知道必须有办法做到这一点。
我正在使用 Visual Studio 2019 和最新版本的 OpenCV。
谢谢大家。
解决方案
推荐阅读
- android - 2 年后更新的 Android 应用程序,无法让它出现在商店中
- zipline - 如何附加到滑索捆绑包
- oracle - 创建函数返回 sys_refcursor
- amazon-web-services - 如何指定 RDS 或 DynamoDB 的子网?
- qt - QT加载资源文件进行调试
- java - Java 8 流 - 将方法传递给过滤器
- docker - 如何在 Docker Toolbox 中访问容器服务器
- python - 我不断收到此错误:第 57 行列表索引超出范围
- php - 在 php 中如何调用或链接另一个 php 页面?
- python - 以相同的方式写入具有多个列表和字典的文件