這是我的理解,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