谢谢你阅读我的问题。
我是python新手,对scipy很感兴趣。我正试图弄清楚如何将浣熊的图像(在scipy misc中)转换成二进制图像(黑白)。这不是在scipy讲座教程中教的。
到目前为止这是我的代码:%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from scipy import misc #here is how you get the racoon image
face = misc.face()
image = misc.face(gray=True)
plt.imshow(image, cmap=plt.cm.gray)
print image.shape
def binary_racoon(image, lowerthreshold, upperthreshold):
img = image.copy()
shape = np.shape(img)
for i in range(shape[1]):
for j in range(shape[0]):
if img[i,j] < lowerthreshold and img[i,j] > upperthreshold:
#then assign black to the pixel
else:
#then assign white to the pixel
return img
convertedpicture = binary_racoon(image, 80, 100)
plt.imshow(convertedpicture, cmap=plt.cm.gist_gray)
我见过其他人使用OpenCV制作图片二进制文件,但我想知道如何通过在像素上循环来这样做?我不知道该给上下限值多少,所以我猜了80和100。还有办法确定吗?