forked from CellProfiler/CellProfiler-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_randomwalkeralgorithm.py
49 lines (30 loc) · 1.02 KB
/
test_randomwalkeralgorithm.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
import numpy
import numpy.testing
import skimage.color
import skimage.measure
import skimage.segmentation
import randomwalkeralgorithm
instance = randomwalkeralgorithm.RandomWalkerAlgorithm
def test_run(image, module, workspace):
module.x_name.value = "example"
module.y_name.value = "RandomWalkerAlgorithm"
module.first_phase.value = 0.5
module.second_phase.value = 0.5
module.beta.value = 130.0
module.run(workspace)
x_data = image.pixel_data
if image.multichannel:
x_data = skimage.color.rgb2gray(x_data)
labels_data = numpy.zeros_like(x_data, numpy.uint)
labels_data[x_data < 0.5] = 1
labels_data[x_data > 0.5] = 2
expected = skimage.segmentation.random_walker(
beta=130.0,
data=x_data,
labels=labels_data,
multichannel=False,
spacing=image.spacing
)
expected = skimage.measure.label(expected)
actual = workspace.get_objects("RandomWalkerAlgorithm")
numpy.testing.assert_array_equal(expected, actual.segmented)