小编Use*_*432的帖子

将图像(np.array)转换为二值图像

感谢您阅读我的问题。

我是 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)

python numpy

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

numpy ×1

python ×1