示例#1
0
def test_skiz():
    f = np.array([
            [0,0,1,1,1],
            [0,0,0,0,0],
            [0,0,0,0,0],
            [1,0,0,0,0]])
    labeled,lines = pymorph.skiz(f!= 0, return_lines=1)
    assert labeled.max() == 2
    assert labeled.min() == 1
    Y,X = np.where(lines)
    assert Y.size
    for y,x in zip(Y,X):
        pos = []
        for dy in (-1, 0, +1):
            for dx in (-1, 0, +1):
                ny = y + dy
                nx = x + dx
                if 0 <= ny < f.shape[0] and 0 <= nx < f.shape[1]:
                    pos.append(labeled[ny,nx])
        assert len(set(pos)) > 1
示例#2
0
img = cv2.cvtColor(img, cv2.cv.CV_BGR2GRAY)
img /= 255

mask = cv2.imread("mask.png")
mask = cv2.cvtColor(mask, cv2.cv.CV_BGR2GRAY)
mask /= 255

print_img(img)
print_img(mask)
new_img = geodesic_dilation(img, mask) * 255
cv2.imwrite("./geodesic_dilation.png", new_img)

# Reconstrucao geodesica
f = np.asarray([0, 0, 1, 3, 3, 7, 7, 7, 7, 5, 2, 1, 1])
g = np.asarray([0, 0, 1, 2, 2, 2, 5, 2, 2, 2, 2, 1, 1])
geodesic_reconstruction_1d(f, g)

# watershed
img = mahotas.imread("dna.jpeg", as_grey=True)
img = img.astype(np.uint8)
# watershed(img)

# skeleton by influence zone (skiz)
img = mahotas.imread("bla.jpeg", as_grey=True)
img = img.astype(np.bool)
skiz = pymorph.skiz(img)
skiz *= 255 / skiz.max()
mahotas.imsave("skiz.png", skiz)
pylab.imshow(skiz)
pylab.show()