0

Hi so I have used a saliency map alongside thresholding to obtain a threshold map of an image. Below is the original, salience map and threshold image respectively:

import cv2

imgpath = r'D:\Documents\University\MSc Data Science\Bath\Modules\Programming\Dissertation\Content Image.jpg'
image = cv2.imread(imgpath)

width = 350
height = 450
dim = (width, height)
 
# resize image
resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)

saliency = cv2.saliency.StaticSaliencyFineGrained_create()
(success, saliencyMap) = saliency.computeSaliency(resized)

# Set threshold for saliency map
ret, threshMap = cv2.threshold((saliencyMap * 255).astype('uint8'), 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
cv2.imshow("Image", resized)
cv2.imshow("Output", saliencyMap)
cv2.imshow("Thresh", threshMap)
cv2.waitKey(0)

The pictures are below:

enter image description here enter image description here enter image description here

The issue I'm having now is, I'm not sure how to put the threshold map over the original image, to get a new image that just has the content of what is in the threshold? Does anyone know what I could do to do this? The resultant image I want is one that copies the threshold image but only the parts of the content image that is white on the threshold map.

Nhyi
  • 373
  • 1
  • 12
  • Use the method `copyTo` with a binary version of the threshold output (0, 1 for each value) as the mask https://docs.opencv.org/4.5.2/d3/d63/classcv_1_1Mat.html#a626fe5f96d02525e2604d2ad46dd574f – flakes Jul 18 '21 at 01:40
  • If your mask has values 0 and 1, try multiplying it with the image to be masked. You can also use Python fancy indexing. – Cris Luengo Jul 18 '21 at 01:41
  • "Below is the original, salience map and threshold image respectively". I do not see any images! – fmw42 Jul 18 '21 at 05:07

0 Answers0