forked from pmneila/morphsnakes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
83 lines (62 loc) · 2.48 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import morphsnakes
import numpy as np
from scipy.misc import imread
from matplotlib import pyplot as ppl
def rgb2gray(img):
"""Convert a RGB image to gray scale."""
return 0.2989*img[:,:,0] + 0.587*img[:,:,1] + 0.114*img[:,:,2]
def circle_levelset(shape, center, sqradius, scalerow=1.0):
"""Build a binary function with a circle as the 0.5-levelset."""
grid = np.mgrid[map(slice, shape)].T - center
phi = sqradius - np.sqrt(np.sum((grid.T)**2, 0))
u = np.float_(phi > 0)
return u
def test_nodule():
# Load the image.
img = imread("testimages/mama07ORI.bmp")[...,0]/255.0
# g(I)
gI = morphsnakes.gborders(img, alpha=1000, sigma=5.48)
# Morphological GAC. Initialization of the level-set.
mgac = morphsnakes.MorphGAC(gI, smoothing=1, threshold=0.31, balloon=1)
mgac.levelset = circle_levelset(img.shape, (100, 126), 20)
# Visual evolution.
ppl.figure()
morphsnakes.evolve_visual(mgac, num_iters=45, background=img)
def test_starfish():
# Load the image.
imgcolor = imread("testimages/seastar2.png")/255.0
img = rgb2gray(imgcolor)
# g(I)
gI = morphsnakes.gborders(img, alpha=1000, sigma=2)
# Morphological GAC. Initialization of the level-set.
mgac = morphsnakes.MorphGAC(gI, smoothing=2, threshold=0.3, balloon=-1)
mgac.levelset = circle_levelset(img.shape, (163, 137), 135, scalerow=0.75)
# Visual evolution.
ppl.figure()
morphsnakes.evolve_visual(mgac, num_iters=110, background=imgcolor)
def test_lakes():
# Load the image.
imgcolor = imread("testimages/lakes3.jpg")/255.0
img = rgb2gray(imgcolor)
# MorphACWE does not need g(I)
# Morphological ACWE. Initialization of the level-set.
macwe = morphsnakes.MorphACWE(img, smoothing=3, lambda1=1, lambda2=1)
macwe.levelset = circle_levelset(img.shape, (80, 170), 25)
# Visual evolution.
ppl.figure()
morphsnakes.evolve_visual(macwe, num_iters=190, background=imgcolor)
def test_confocal3d():
# Load the image.
img = np.load("testimages/confocal.npy")
# Morphological ACWE. Initialization of the level-set.
macwe = morphsnakes.MorphACWE(img, smoothing=1, lambda1=1, lambda2=2)
macwe.levelset = circle_levelset(img.shape, (30, 50, 80), 25)
# Visual evolution.
morphsnakes.evolve_visual3d(macwe, num_iters=200)
if __name__ == '__main__':
print """"""
test_nodule()
test_starfish()
test_lakes()
test_confocal3d()
ppl.show()