感谢您阅读我的问题。
我是 python 新手,对 scipy 感兴趣。我试图弄清楚如何将浣熊的图像(在 scipy 杂项中)转换为二进制图像(黑色,白色)。scipy-lecture 教程中没有讲授这一点。
到目前为止,这是我的代码:
%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 …Run Code Online (Sandbox Code Playgroud)