I have managed to get a saliency map of an image using the following code below. Here it obtains the saliency map as well as the inverse saliency map and then applies the results to the image in order to get the foreground and background of the image.
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)
I get the following output for the foreground and background respectively when this image has been put in:
I was wondering, how to improve the brightness or features of the foreground so the features are a lot more prominant and the image is brighter if that makes sense? Any idea what could be done? Cheers



You can use cv2.normalize() in Python/OpenCV to increase brightness.
Input:
Result: