0
import numpy as np
import scipy
import pylab
import pymorph
import mahotas
from scipy import ndimage

image = mahotas.imread('img.tiff')

pylab.imshow(image)
pylab.show()

I want to select (threshold) brown pixels (vessels) on medical image and compute the area which they do represent. How can I do that in Python like in Matlab or C++? Are there any good examples I could not find?

Thank you

4

1 回答 1

0

我不知道您对“棕色”的规则是什么,但大概是这样的(在 RGB 颜色空间中):

0.5 <= r < 0.75 and 0.25 <= g < 0.375 and b < 0.1

Anndimage只是一个 3D 像素数组,其中第三维是颜色平面。换句话说,对于 RGBA 图像,image[0, 0, 0]像素的红色值是像素(0, 0)image[0, 0, 1]绿色值(0, 0),等等。

所以,你有一个像素数组。您想要计算与该规则匹配的所有像素。您不需要任何特定于图像的功能。只需使用您最喜欢的numpy机制将函数应用于每行和每列的所有平面,即可获得一个 2x2 的布尔数组。例如:

browns = ((image[:,:,0] >= 0.50) & (image[:,:,0] < 0.75) &
          (image[:,:,1] >= 0.25) & (image[:,:,1] < 0.375) &
          (image[:,:,2] < 0.1))
于 2013-07-03T21:22:59.673 回答