我希望你能将结果数组转换为二进制的是/否。
我想到了以下代码:
我想到了以下代码:
img = PIL.Image.open(filename)
array = numpy.array(img)
thresholded_array = numpy.copy(array)
brightest = numpy.amax(array)
threshold = brightest/2
for b in xrange(490):
for c in xrange(490):
if array[b][c] > threshold:
thresholded_array[b][c] = 255
else:
thresholded_array[b][c] = 0
out=PIL.Image.fromarray(thresholded_array)
但是逐个值地迭代数组非常慢,我知道一定有更快的方法,那么最快的方法是什么?