cv2.threshold() 中的哪些设置会影响此图像?
What settings in cv2.threshold() to threshold this image?
我想在 OpenCV 中将此图像转换为灰度,然后找到对其设置阈值的设置。我想对头骨内部的黑色空间设置阈值。有人可以使用 OpenCV 写出 Python 脚本吗?
我转换为灰度:gray = cv2.cvtColor(pic, cv2.COLOR_BGR2GRAY)
当我这样做时 (ret, thresh) = cv2.threshold(gray, 177, 255, cv2.THRESH_BINARY)
我得到一张黑色图像。
当我这样做时 (ret, thresh) = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY)
整个头变成了白色斑点。
如果我没有正确理解您的目标,这是我的建议。正如@stateMachine 所说,它使用 Otsu 的阈值。
import cv2
im = cv2.imread("IScDg.png")
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
# Your first method
(_, thresh1) = cv2.threshold(gray, 177, 255, cv2.THRESH_BINARY)
# Your second method
(ret, thresh2) = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY)
# Proposed method
(_, thresh3) = cv2.threshold(gray, 0, 1, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
different thresholds on your image
我经常涂OTSU,效果很好。
ret,gray = cv2.threshold(gray,100,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
我想在 OpenCV 中将此图像转换为灰度,然后找到对其设置阈值的设置。我想对头骨内部的黑色空间设置阈值。有人可以使用 OpenCV 写出 Python 脚本吗?
我转换为灰度:gray = cv2.cvtColor(pic, cv2.COLOR_BGR2GRAY)
当我这样做时 (ret, thresh) = cv2.threshold(gray, 177, 255, cv2.THRESH_BINARY)
我得到一张黑色图像。
当我这样做时 (ret, thresh) = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY)
整个头变成了白色斑点。
如果我没有正确理解您的目标,这是我的建议。正如@stateMachine 所说,它使用 Otsu 的阈值。
import cv2
im = cv2.imread("IScDg.png")
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
# Your first method
(_, thresh1) = cv2.threshold(gray, 177, 255, cv2.THRESH_BINARY)
# Your second method
(ret, thresh2) = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY)
# Proposed method
(_, thresh3) = cv2.threshold(gray, 0, 1, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
different thresholds on your image
我经常涂OTSU,效果很好。
ret,gray = cv2.threshold(gray,100,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)