0

我已经设法使用下面的代码获得图像的显着图。在这里,它获得显着图以及逆显着图,然后将结果应用于图像,以获得图像的前景和背景。

import cv2
import numpy as np

def SalienceMaps(image_path):
    
    image = cv2.imread(image_path)
    
    dimensions = (350, 450)    
    resized = cv2.resize(image, dimensions, interpolation = cv2.INTER_AREA)
    
    saliency = cv2.saliency.StaticSaliencyFineGrained_create()
    (success, saliencyMap) = saliency.computeSaliency(resized)
    
    (B, G, R) = cv2.split(resized)
    
    salBlue = B * saliencyMap.astype(saliencyMap.dtype)
    salGreen = G * saliencyMap.astype(saliencyMap.dtype)
    salRed= R * saliencyMap.astype(saliencyMap.dtype)
    
    salBlue = salBlue.astype("uint8")
    salGreen = salGreen.astype("uint8")
    salRed = salRed.astype("uint8")
    
    reduction = np.ones((450,350))
    inverse = reduction - saliencyMap
    
    inverseBlue = B * inverse.astype(inverse.dtype)
    inverseGreen = G * inverse.astype(inverse.dtype)
    inverseRed = R * inverse.astype(inverse.dtype)
    
    inverseBlue = inverseBlue.astype("uint8")
    inverseGreen = inverseGreen.astype("uint8")
    inverseRed = inverseRed.astype("uint8")
    
    main = cv2.merge((salBlue, salGreen, salRed))
    inverse = cv2.merge((inverseBlue, inverseGreen, inverseRed))

    return (main, inverse)

(main, inverse) = SalienceMaps("Content Image.jpg")
cv2.imshow("Image", main)
cv2.imshow("Image 2", inverse)
cv2.waitKey(0)

放入此图像后,我分别得到前景和背景的以下输出:

在此处输入图像描述 在此处输入图像描述在此处输入图像描述

我想知道,如何提高前景的亮度或特征,使特征更加突出,如果有意义的话,图像会更亮?知道可以做什么吗?干杯

4

1 回答 1

0

您可以在 Python/OpenCV 中使用 cv2.normalize() 来增加亮度。

输入:

在此处输入图像描述

import cv2
import numpy as np

# Read images
img = cv2.imread('img.png')

# stretch mask to full dynamic range
result = cv2.normalize(img, None, alpha=0, beta=350, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8U)

# write results
cv2.imwrite("img_enhanced.png", result)

# show results
cv2.imshow("img", img)
cv2.imshow("result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()

结果:

在此处输入图像描述

于 2021-07-21T15:52:49.667 回答