我已经设法使用下面的代码获得图像的显着图。在这里,它获得显着图以及逆显着图,然后将结果应用于图像,以获得图像的前景和背景。
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)
放入此图像后,我分别得到前景和背景的以下输出:
我想知道,如何提高前景的亮度或特征,使特征更加突出,如果有意义的话,图像会更亮?知道可以做什么吗?干杯