这是我的理解,thresholding是一个阶梯函数意味着像素值四舍五入每一步。例如。像素值33将四舍五入为32(假设有32的阈值)。在我的代码中,我正在尝试完成阈值处理,但我不认为我正在尝试它。有人可以指导我什么我失踪?如何创建图像的阈值?
import pylab as plt
import matplotlib.image as mpimg
import numpy as np
img = np.uint8(mpimg.imread("abby.jpg"))
img = np.uint8((0.2126* img[:,:,0]) + \
np.uint8(0.7152 * img[:,:,1]) +\
np.uint8(0.0722 * img[:,:,2]))
threshold = 128
for row in img: ## trying to loop through to find if each image pixel > threshold
for col in row:
if col > threshold:
col = threshold
else:
col = 0
plt.imshow(img,cmap=plt.cm.gray)
plt.show()
请阅读K.Sarkar和我之间的简单代码的评论讨论。感谢他在Python中的专业知识。 – saurabheights