forked from CellProfiler/CellProfiler-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_imagegradient.py
46 lines (31 loc) · 1.25 KB
/
test_imagegradient.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
import cellprofiler.image
import numpy
import numpy.testing
import skimage.filters.rank
import skimage.morphology
import imagegradient
instance = imagegradient.ImageGradient
def test_run(image, module, image_set, workspace):
module.x_name.value = "example"
module.y_name.value = "ImageGradient"
if image.dimensions == 3:
module.structuring_element.shape = "ball"
module.run(workspace)
actual = image_set.get_image("ImageGradient")
data = image.pixel_data
data = skimage.img_as_uint(data)
disk = skimage.morphology.disk(1)
if image.dimensions == 3 or image.multichannel:
expected_data = numpy.zeros_like(data)
for z, img in enumerate(data):
expected_data[z] = skimage.filters.rank.gradient(img, disk)
else:
expected_data = skimage.filters.rank.gradient(data, disk)
# CellProfiler converts Image data according to MatLab standards. Remove this and test against
# expected_data once MatLab support is removed. Until then, use the Image constructro to convert the data
# a la MatLab before comparison.
expected = cellprofiler.image.Image(
image=expected_data,
dimensions=3
)
numpy.testing.assert_array_equal(expected.pixel_data, actual.pixel_data)