【问题标题】:How to improve intensity contrast in image?如何提高图像的强度对比度?
【发布时间】:2017-11-29 00:17:24
【问题描述】:

我的图像与背景的对比度非常低。 两个箭头之间的第一条线是低对比度的线。 第二行没问题。请看下图。

原图如下图。

我使用以下方法来增强灰度的对比度。 首先将图像更改为灰色并使用以下方法。

cv::Mat temp;
for (int i = 0; i < 1; i++) // number of iterations has to be adjusted
{
    cv::threshold(image, temp, 0, 255, CV_THRESH_BINARY| CV_THRESH_OTSU);// 
    cv::bitwise_and(image, temp, image);
    cv::normalize(image, image, 0, 255, cv::NORM_MINMAX, -1, temp);     
}

我的图像在灰度中的对比度略高,但是在灰度或彩色中有没有比这更好的方法?

【问题讨论】:

标签: image opencv image-processing


【解决方案1】:

我会查看histogram equalization,这可能会满足您的需求。基本(全局)均衡甚至adaptive 可以产生很好的效果。可能需要针对自适应方法调整参数(目前使用文档示例中的那个)。

我得到(全局均衡 - 左;自适应均衡 - 右):

均衡完成后,您可能会在阈值处理方面获得更好的运气(尽管您的示例对比度非常低):

从那里,您可以使用标准轮廓/形状匹配等来尝试找到您的第一条黑线的位置。

来自

import cv2
import matplotlib.pyplot as plt
import numpy as np

raw_img_load = cv2.imread('H1o8X.png')

imgr = cv2.cvtColor(raw_img_load,cv2.COLOR_BGR2GRAY)
clahe = cv2.createCLAHE(clipLimit=30.0, tileGridSize=(8,8))
imgray_ad = clahe.apply(imgr)#adaptive
imgray = cv2.equalizeHist(imgr)#global
res = np.hstack((imgray,imgray_ad))#so we can plot together

plt.imshow(res,cmap='gray')
plt.show()

ret,thresh = cv2.threshold(imgray_ad,150,255,type=cv2.THRESH_BINARY+cv2.THRESH_OTSU)
plt.imshow(thresh,cmap='gray')
plt.show()

编辑:基于@Doleron 的回答,对于这个特殊问题,我建议使用fastNlMeansDenoising(在任何直方图均衡之前应用)。但是请注意,对于高分辨率图像/时间敏感的图像处理,它可能是一个缓慢的功能。

【讨论】:

  • 谢谢好主意。
【解决方案2】:

@Antoine Zambelli 的答案很棒,而且是正确的。无论如何,我在这里挖了一些,并尝试使用fastNlMeansDenoising去除之前的噪音以改善最终结果:

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/photo.hpp"

using namespace cv;
using cv::CLAHE;

int main(int argc, char** argv) {
    Mat srcImage = imread("H1o8X.png", CV_LOAD_IMAGE_GRAYSCALE);
    imshow("src", srcImage);

    Mat denoised;

    fastNlMeansDenoising(srcImage, denoised, 10);

    Mat image = denoised;

    Ptr<CLAHE> clahe = createCLAHE();
    clahe->setClipLimit(30.0);
    clahe->setTilesGridSize(Size(8, 8));
    Mat imgray_ad;
    clahe->apply(image, imgray_ad);
    Mat imgray;
    cv::equalizeHist(image, imgray);
    imshow("imgray_ad", imgray_ad);
    imshow("imgray", imgray);

    Mat thresh;
    threshold(imgray_ad, thresh, 150, 255, THRESH_BINARY | THRESH_OTSU);
    imshow("thresh", thresh);

    Mat result;
    Mat kernel = Mat::ones(8, 8, CV_8UC1);

    erode(thresh, result, kernel);
    imshow("result", result);

    waitKey();
    return 0;
}

【讨论】:

  • +1 用于腐蚀以清理最终结果!我对fastNlMeansDenoising 完全无动于衷。
猜你喜欢
  • 1970-01-01
  • 2020-04-21
  • 1970-01-01
  • 1970-01-01
  • 2017-09-27
  • 2011-05-07
  • 1970-01-01
  • 2021-10-25
  • 2020-01-10
相关资源
最近更新 更多