因此,我试图制作一个能够将眼球血管的一部分作为我数学课程的一部分的功能,但无论我输入什么阈值,我都会得到相同的结果,所以我认为我必须做一些事情以下代码非常错误:
def threshold_image(retina, threshold):
tImage = retina
for pixel in tImage.shape:
if pixel <=threshold:
pixel=1
else:
pixel=0
return tImage
img2 = threshold_image(img, 3)
io.imshow(img2, cmap=cm.Greys_r)
plt.show()
我的计划是,制作一个遍历图片每个像素的函数,然后应用阈值,如果它高于阈值,则像素将变为0(黑色),如果它在其中,则为1(白色)。然而,我目前正在得到相同的图片,我给它的结果
你正在迭代tImage.shape
:你的pixel
只得到图像的两个值h
和w
。你没有迭代像素本身。
尝试:
for pixel in tImage:
pixel = 0 if pixel > thr else 1
当你在这里时,简单地说有什么问题
tImage = img < threshold