c++ - 使用 openCV 放大高强度

标签 c++ opencv

我有一张图像具有高强度区域,我想放大这些强度。我在 Matlab 中通过将 (0,255) 中的整数数组转换为 (0,1) 中的 float ,然后对每个值进行平方和最后乘以 255 并转换回整数。

如何在 openCV 中完成这样的事情?有没有办法逐个访问元素?即便如此,我想这将是低效的,并且想知道是否有 openCV 方法经过矢量化或其他优化来实现这一点。

最佳答案

给定输入灰度图像:

enter image description here

你的算法的结果是:

enter image description here

您可以:

  • 使用 convertTo 进行转换和缩放。
  • 使用元素级乘法 mul 对每个像素求平方,或使用 pow 计算任意数。

这是简单的代码:

#include <opencv2/opencv.hpp>
using namespace cv;

int main()
{
    Mat img = imread("path_to_image", IMREAD_GRAYSCALE);
    imshow("Original", img);

    // converting to float in (0,1)
    img.convertTo(img, CV_32F, 1.0 / 255.0);
    // power with an arbitrary number. Use 2 to square
    pow(img, 2, img);
    // multiplying by 255 and back to integer
    img.convertTo(img, CV_8U, 255.0);

    imshow("Result", img);
    waitKey();

    return 0;
}

关于c++ - 使用 openCV 放大高强度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35075415/

相关文章:

c++ - 将链表从 C 传递到 C++

c++ - 写入动态二维数组时访问冲突...有时

c++ - Halide - while 循环等效

c++ - 与 libstdc++-6.dll 相关的 OpenCV 应用程序崩溃

python - 查找所有圆形对象

c++ - OpenCV - 缺少调试 DLL 库

c++ - QuantLib:需要 Garch 帮助

c++ - 为什么 int 加上 uint 返回 uint?

c++ - Win32API : How to request embedded windows event notifications out to a parent window

c++ - 多 channel Mat显示功能