<tfoot id='QZNvG'></tfoot><legend id='QZNvG'><style id='QZNvG'><dir id='QZNvG'><q id='QZNvG'></q></dir></style></legend>

        <small id='QZNvG'></small><noframes id='QZNvG'>

          <bdo id='QZNvG'></bdo><ul id='QZNvG'></ul>
      1. <i id='QZNvG'><tr id='QZNvG'><dt id='QZNvG'><q id='QZNvG'><span id='QZNvG'><b id='QZNvG'><form id='QZNvG'><ins id='QZNvG'></ins><ul id='QZNvG'></ul><sub id='QZNvG'></sub></form><legend id='QZNvG'></legend><bdo id='QZNvG'><pre id='QZNvG'><center id='QZNvG'></center></pre></bdo></b><th id='QZNvG'></th></span></q></dt></tr></i><div id='QZNvG'><tfoot id='QZNvG'></tfoot><dl id='QZNvG'><fieldset id='QZNvG'></fieldset></dl></div>

        在 OpenCV 中使用 C++ 是否有与 Matlab 的 imadjust 等效

        时间:2023-09-18
      2. <legend id='YUVrB'><style id='YUVrB'><dir id='YUVrB'><q id='YUVrB'></q></dir></style></legend>

        <i id='YUVrB'><tr id='YUVrB'><dt id='YUVrB'><q id='YUVrB'><span id='YUVrB'><b id='YUVrB'><form id='YUVrB'><ins id='YUVrB'></ins><ul id='YUVrB'></ul><sub id='YUVrB'></sub></form><legend id='YUVrB'></legend><bdo id='YUVrB'><pre id='YUVrB'><center id='YUVrB'></center></pre></bdo></b><th id='YUVrB'></th></span></q></dt></tr></i><div id='YUVrB'><tfoot id='YUVrB'></tfoot><dl id='YUVrB'><fieldset id='YUVrB'></fieldset></dl></div>
          <tbody id='YUVrB'></tbody>

          <small id='YUVrB'></small><noframes id='YUVrB'>

            <bdo id='YUVrB'></bdo><ul id='YUVrB'></ul>

            • <tfoot id='YUVrB'></tfoot>

                • 本文介绍了在 OpenCV 中使用 C++ 是否有与 Matlab 的 imadjust 等效的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我习惯于使用 imadjust 在 Matlab 中进行对比度增强.OpenCV 中是否有任何等效的功能?

                  谷歌搜索提供了

                  输出调整后的图像:

                  I'm used to contrast enhancement in Matlab using imadjust. Is there any equivalent function in OpenCV?

                  A google search gives the OpenCV documentation on brightness and contrast enhancement but it uses for loops which might be inefficient. Even if we make it efficient by using Matrix expressions, it is not equivalent to what imadjust does.

                  Is there any in-built function in OpenCV or any efficient method for the task?

                  I saw related posts but either they link to the OpenCV doc I mentioned above or they suggest Histogram Equalization and thresholding. I prefer imadjust to histogram equalization and thresholding doesn't seem to perform contrast enhancement as such.

                  Any help on this is appreciated.

                  解决方案

                  There's no builtin solution in OpenCV to perform histogram stretching, but you can do it easily in a loop.

                  imadjust allows to select a tolerance for upper and lower bounds, or the bounds directly, so you need a little more logic than a simple for loop.

                  You can use the example below as a reference while implementing your own:

                  #include <opencv2opencv.hpp>
                  #include <vector>
                  #include <algorithm>
                  
                  using namespace std;
                  using namespace cv;
                  
                  void imadjust(const Mat1b& src, Mat1b& dst, int tol = 1, Vec2i in = Vec2i(0, 255), Vec2i out = Vec2i(0, 255))
                  {
                      // src : input CV_8UC1 image
                      // dst : output CV_8UC1 imge
                      // tol : tolerance, from 0 to 100.
                      // in  : src image bounds
                      // out : dst image buonds
                  
                      dst = src.clone();
                  
                      tol = max(0, min(100, tol));
                  
                      if (tol > 0)
                      {
                          // Compute in and out limits
                  
                          // Histogram
                          vector<int> hist(256, 0);
                          for (int r = 0; r < src.rows; ++r) {
                              for (int c = 0; c < src.cols; ++c) {
                                  hist[src(r,c)]++;
                              }
                          }
                  
                          // Cumulative histogram
                          vector<int> cum = hist;
                          for (int i = 1; i < hist.size(); ++i) {
                              cum[i] = cum[i - 1] + hist[i];
                          }
                  
                          // Compute bounds
                          int total = src.rows * src.cols;
                          int low_bound = total * tol / 100;
                          int upp_bound = total * (100-tol) / 100;
                          in[0] = distance(cum.begin(), lower_bound(cum.begin(), cum.end(), low_bound));
                          in[1] = distance(cum.begin(), lower_bound(cum.begin(), cum.end(), upp_bound));
                  
                      }
                  
                      // Stretching
                      float scale = float(out[1] - out[0]) / float(in[1] - in[0]);
                      for (int r = 0; r < dst.rows; ++r)
                      {
                          for (int c = 0; c < dst.cols; ++c)
                          {
                              int vs = max(src(r, c) - in[0], 0);
                              int vd = min(int(vs * scale + 0.5f) + out[0], out[1]);
                              dst(r, c) = saturate_cast<uchar>(vd);
                          }
                      }
                  }
                  
                  int main()
                  {
                      Mat3b img = imread("path_to_image");
                  
                      Mat1b gray;
                      cvtColor(img, gray, COLOR_RGB2GRAY);
                  
                      Mat1b adjusted;
                      imadjust(gray, adjusted);
                  
                      // int low_in, high_in, low_out, high_out
                      // imadjust(gray, adjusted, 0, Vec2i(low_in, high_in), Vec2i(low_out, high_out));
                  
                      return 0;
                  }
                  

                  Input image:

                  Output adjusted image:

                  这篇关于在 OpenCV 中使用 C++ 是否有与 Matlab 的 imadjust 等效的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将 2D 像素阵列旋转 90 度 下一篇:openCV 2.4.10 bwlabel - 连接组件

                  相关文章

                  最新文章

                  <tfoot id='3kf2b'></tfoot>
                  <legend id='3kf2b'><style id='3kf2b'><dir id='3kf2b'><q id='3kf2b'></q></dir></style></legend>
                  <i id='3kf2b'><tr id='3kf2b'><dt id='3kf2b'><q id='3kf2b'><span id='3kf2b'><b id='3kf2b'><form id='3kf2b'><ins id='3kf2b'></ins><ul id='3kf2b'></ul><sub id='3kf2b'></sub></form><legend id='3kf2b'></legend><bdo id='3kf2b'><pre id='3kf2b'><center id='3kf2b'></center></pre></bdo></b><th id='3kf2b'></th></span></q></dt></tr></i><div id='3kf2b'><tfoot id='3kf2b'></tfoot><dl id='3kf2b'><fieldset id='3kf2b'></fieldset></dl></div>
                • <small id='3kf2b'></small><noframes id='3kf2b'>

                      • <bdo id='3kf2b'></bdo><ul id='3kf2b'></ul>