임계 값은 각 단계에서 픽셀 값이 반올림됨을 의미하는 단계 함수라는 것을 알고 있습니다. 예 : 픽셀 값 33은 32로 반올림됩니다 (32의 임계 값이 있다고 가정). 내 코드에서 나는 thresholding을 수행하려고 노력하고 있지만 나는 그것을 acheieving 생각하지 않습니다. 누군가 내가 놓친 부분에 관해 나를 안내 할 수 있습니까?이미지의 임계 값은 어떻게 만듭니 까?
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와 me 사이의 코멘트 토론을 읽으십시오. 그의 파이썬 전문성 덕분입니다. – saurabheights