我怎样才能调整℃的OpenCV的反差? [英] How can I adjust contrast in OpenCV in C?

查看:141
本文介绍了我怎样才能调整℃的OpenCV的反差?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想调整对比度/亮度灰度图像中突出显示的图像与白人在opencv的C.我怎样才能做到这一点?有没有使这个任务OpenCV的任何功能?

I'm just trying to adjust contrast/ brightness in an image in gray scale to highlight whites in that image with Opencv in C. How can I do that? is there any function that makes this task in opencv?

原图:

修改图片:

在此先感谢!

推荐答案

我觉得你可以通过两种方式在这里调节对比度:

I think you can adjust contrast here in two ways:

1) 直方图均衡化:

1) Histogram Equalization :

但是,当我试图与你的形象,结果并没有如你预期。检查下面的:

But when i tried this with your image, result was not as you expected. Check it below:

2)的阈值

在这里,我比较投入与任意值的每个像素值(这是我花了 127 )。以下是已经内置功能OpenCV的逻辑。 但请记住,输出为二值图像,因为你没有灰度。

Here, i compared each pixel value of input with an arbitrary value ( which i took 127). Below is the logic which has inbuilt function in opencv. But remember, output is Binary image, not grayscale as you did.

If (input pixel value >= 127):
    ouput pixel value = 255
else:
    output pixel value = 0

和下面是我得到的结果:

And below is the result i got :

对于这一点,你可以使用 <一个href=\"http://opencv.itseez.com/modules/imgproc/doc/miscellaneous_transformations.html?highlight=cv2.threshold#threshold\">Threshold功能 <一个href=\"http://opencv.itseez.com/modules/core/doc/operations_on_arrays.html?highlight=cv2.add#compare\">compare功能

For this, you can use Threshold function or compare function

3)如果您是强制性得到灰度图像作为输出,操作如下

(code在OpenCV的Python的,但每一个功能,对应的C函数在opencv.itseez.com可用)

(code is in OpenCV-Python, but for every-function, corresponding C functions are available in opencv.itseez.com)

for each pixel in image:
   if pixel value >= 127: add 'x' to pixel value.
   else : subtract 'x' from pixel value. 

(x是任意的值。)因此间亮和暗像素的增加的差异。

( 'x' is an arbitrary value.) Thus difference between light and dark pixels increases.

img = cv2.imread('brain.jpg',0)

bigmask = cv2.compare(img,np.uint8([127]),cv2.CMP_GE)
smallmask = cv2.bitwise_not(bigmask)

x = np.uint8([90])
big = cv2.add(img,x,mask = bigmask)
small = cv2.subtract(img,x,mask = smallmask)
res = cv2.add(big,small)

和下面是所得结果:

这篇关于我怎样才能调整℃的OpenCV的反差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆