蟒蛇血管图像分割

时间:2017-11-28 10:01:18

标签: python-3.x computer-vision data-modeling image-segmentation

所以我试图制作一个能够将眼球血管的一部分作为我数学课程的一部分的功能,但无论我输入什么阈值,我都会得到相同的结果,所以我认为我必须在以下代码中做了一些非常错误的事情:

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(白色)。但是,我目前只是得到了相同的图片,结果我给了它

1 个答案:

答案 0 :(得分:1)

您正在对tImage.shape进行迭代:您的pixel只获得图片的两个值hw。你没有迭代像素本身。

尝试:

for pixel in tImage:
  pixel = 0 if pixel > thr else 1

当你在这里时,简单的

是什么问题
tImage = img < threshold
相关问题