显着性图的阈值图像如何?

How Can I A Threshold Image of a Salience Map?

我目前有一张图像的显着图如下,光谱显着图和细粒度显着图如下通过以下代码获得:

import cv2

imgpath = r'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.StaticSaliencySpectralResidual_create()
(success, saliencyMap) = saliency.computeSaliency(resized)
saliencyMap = (saliencyMap * 255).astype("uint8")
cv2.imshow("Image", resized)
cv2.imshow("Output", saliencyMap)
cv2.waitKey(0)
cv2.destroyAllWindows()

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

这些都是有道理的,我明白为什么会得到它们。

但是,当我尝试使用以下代码获取阈值图时:

ret, threshMap = cv2.threshold(saliencyMap.astype("uint8"), 120, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
cv2.imshow("Image", resized)
cv2.imshow("Output", saliencyMap)
cv2.imshow("Thresh", threshMap)
cv2.waitKey(0)

我得到如下图片:

不太清楚为什么会这样,因为我很确定我已经按照我在网上找到的所有内容进行操作,非常感谢任何帮助。

saliencyMap 的值介于 0 和 1 之间。您需要将值重新调整为 0-255 范围。 然后,决定您是想要 otsu 阈值还是手动阈值。给定值 120 对 Otsu 二值化方法没有影响,因为它会自动确定阈值。

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)
cv2.destroyAllWindows()

输出大津二值化:

或阈值

的手动值120输入
ret, threshMap = cv2.threshold((saliencyMap * 255).astype('uint8'), 120, 255, cv2.THRESH_BINARY)