forked from CellProfiler/CellProfiler-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tophattransform.py
76 lines (49 loc) · 1.86 KB
/
test_tophattransform.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
import cellprofiler.image
import numpy.testing
import pytest
import skimage.data
import skimage.morphology
import tophattransform
instance = tophattransform.TopHatTransform
@pytest.fixture(
scope="module",
params=[
(skimage.data.camera()[0:128, 0:128], 2),
(numpy.tile(skimage.data.camera()[0:32, 0:32], (2, 1)).reshape(2, 32, 32), 3)
],
ids=[
"grayscale_image",
"grayscale_volume"
]
)
def image(request):
data, dimensions = request.param
return cellprofiler.image.Image(image=data, dimensions=dimensions)
def test_run_black_tophat(image, module, image_set, workspace):
module.x_name.value = "example"
module.y_name.value = "TopHatTransform"
module.operation_name.value = "Black top-hat transform"
if image.volumetric:
module.structuring_element.value = "ball,1"
structure = skimage.morphology.ball(1)
else:
module.structuring_element.value = "disk,1"
structure = skimage.morphology.disk(1)
module.run(workspace)
actual = image_set.get_image("TopHatTransform")
desired = skimage.morphology.black_tophat(image.pixel_data, structure)
numpy.testing.assert_array_equal(actual.pixel_data, desired)
def test_run_white_tophat(image, module, image_set, workspace):
module.x_name.value = "example"
module.y_name.value = "TopHatTransform"
module.operation_name.value = "White top-hat transform"
if image.volumetric:
module.structuring_element.value = "ball,1"
structure = skimage.morphology.ball(1)
else:
module.structuring_element.value = "disk,1"
structure = skimage.morphology.disk(1)
module.run(workspace)
actual = image_set.get_image("TopHatTransform")
desired = skimage.morphology.white_tophat(image.pixel_data, structure)
numpy.testing.assert_array_equal(actual.pixel_data, desired)