Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用阈值图像更改实际图像中的亮度值_Python_Python 3.x_Image_Numpy_Opencv - Fatal编程技术网

Python 使用阈值图像更改实际图像中的亮度值

Python 使用阈值图像更改实际图像中的亮度值,python,python-3.x,image,numpy,opencv,Python,Python 3.x,Image,Numpy,Opencv,我想做什么: img = cv2.imread('1.bmp') img = cv2.GaussianBlur(img,(5,5),0) """ Take the image and slipt it into the HSV colour spectrem """ h,s,v= cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV)) """ Equalise the histogram for the V value """ eq_V = c

我想做什么:

img = cv2.imread('1.bmp')


img = cv2.GaussianBlur(img,(5,5),0)

""" Take the image and slipt it into the HSV colour spectrem """

h,s,v= cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))

""" Equalise the histogram for the V value """

eq_V = cv2.equalizeHist(v)

""" Merge all the values back into one image """

eq_image = cv2.cvtColor(cv2.merge([h, s, eq_V]), cv2.COLOR_HSV2BGR)

ret1,th1 = cv2.threshold(eq_image,127,255,cv2.THRESH_BINARY)


[rows, columns, channels] = img.shape

blacks = np.zeros((rows,columns,channels))
whites = np.zeros((rows,columns,channels))



for row in range(rows):
    for column in range(columns):
        if th1[row,column].all() == 0:
            """ Equalise the v value """
            blacks[row,column] = v[row,column]

        else:
            """ Equalise the v value """
            whites[row,column] = v[row,column]


addTogether = cv2.add(blacks,whites)


cv2.imshow("frame", addTogether.astype(np.uint8))
cv2.waitKey(0)
cv2.destroyAllWindows()
  • 拍照
  • 对图像应用高斯滤波器
  • 基于OpenCv equaliseHist函数对图像进行均衡
  • 从均衡图像中获取阈值图像:
  • 如果阈值图像中的像素等于黑色,则在实际图像中降低该像素的亮度,如果阈值图像中的白色增加实际图像中的亮度

    以下是我目前拥有的代码:

    img = cv2.imread('1.bmp')
    
    
    img = cv2.GaussianBlur(img,(5,5),0)
    
    """ Take the image and slipt it into the HSV colour spectrem """
    
    h,s,v= cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))
    
    """ Equalise the histogram for the V value """
    
    eq_V = cv2.equalizeHist(v)
    
    """ Merge all the values back into one image """
    
    eq_image = cv2.cvtColor(cv2.merge([h, s, eq_V]), cv2.COLOR_HSV2BGR)
    
    ret1,th1 = cv2.threshold(eq_image,127,255,cv2.THRESH_BINARY)
    
    
    [rows, columns, channels] = img.shape
    
    blacks = np.zeros((rows,columns,channels))
    whites = np.zeros((rows,columns,channels))
    
    
    
    for row in range(rows):
        for column in range(columns):
            if th1[row,column].all() == 0:
                """ Equalise the v value """
                blacks[row,column] = v[row,column]
    
            else:
                """ Equalise the v value """
                whites[row,column] = v[row,column]
    
    
    addTogether = cv2.add(blacks,whites)
    
    
    cv2.imshow("frame", addTogether.astype(np.uint8))
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    
    我的问题

    我正在努力的部分是第4步。如上所述。我目前正在构建一个基于whats black和whats what what what what what what what what white的图像,然后将这些图像添加到一起,以返回到我的原始图像状态

    我似乎无法做/弄清楚的是如何调整图像hsv的v值,然后如何将整个图像与色调和饱和度值旁边的新v值合并在一起

    来自最新尝试的图像


    @Sounak im使用该行表示如果
    th1
    中的像素是黑色的,那么我想更改该像素的亮度(在这种情况下,将其稍微暗一点)在
    eq_图像
    中,如果在
    th1
    中为白色,则在
    eq_图像
    中将像素的亮度更改为稍亮一点,我认为您的
    addTogether
    v
    完全相同,但有3个通道,因为我不确定如何在
    黑色
    白色
    numpy数组中调整
    v
    th\u v\u up=(cv2.bitwise\u和(v,th1)+cv2.bitwise\u和(np.ones(v.shape).astype(np.uint8)*5,th1))
    将与
    th1
    中的白色像素相对应的像素值增加5
    th1\u n=cv2。按位\u非(th1)
    按位\u向下=(cv2.按位\u和(v,th1\u n)-cv2.按位\u和(np.one(v.shape).aType(np.uint8)*5,th1\n))
    @Sounak im使用该行表示如果
    th1
    中的像素是黑色的,那么我想更改该像素的亮度(在这种情况下,使其稍微暗一点)在
    eq_图像
    中,如果在
    th1
    中为白色,则在
    eq_图像
    中将像素的亮度更改为稍亮一点,我认为您的
    addTogether
    v
    完全相同,但有3个通道,因为我不确定如何在
    黑色
    白色
    numpy数组中调整
    v
    th\u v\u up=(cv2.bitwise\u和(v,th1)+cv2.bitwise\u和(np.ones(v.shape).astype(np.uint8)*5,th1))
    将把与
    th1
    中的白色像素对应的像素值增加5
    th1\u n=cv2.bitwise\u not(th1)
    th\u v\u down=(cv2.bitwise\u和(v,th1\u n)-cv2.bitwise\u和(np.ones(v.shape).astype(np.uint8)*5,th1\u n))