def threshold_value(img):
"""
Returns a threshold value (0.9 or 0.98) based on whether any slice
of the image within a central box is enterely white (white is a bitch!)
0.9 or 0.98 come simply from a lot of experimentation.
"""
is_color = len(img.shape) == 3
is_grey = len(img.shape) == 2
if is_color:
gray = cv2.cvtColor(gray,cv2.COLOR_BGR2GRAY)
elif is_grey:
gray = img.copy()
slices = gray.mean(axis = 1)[20:gray.shape[0]-30]
is_white = any(x > 0.9*255 for x in slices)
if is_white:
return 0.98
else:
return 0.9
morphology_utils.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录