Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ttk
spam
Commits
fafcf3a1
Commit
fafcf3a1
authored
Oct 11, 2020
by
Gustavo Pinzon
Browse files
Test for spam.labels.convexFillHoles()
parent
da829e7c
Pipeline
#50628
passed with stages
in 12 minutes and 49 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/test_label.py
View file @
fafcf3a1
...
...
@@ -758,5 +758,42 @@ class TestFunctionLabel(unittest.TestCase):
newCOM
=
spam
.
label
.
centresOfMass
(
imLab2
)[
-
1
]
self
.
assertEqual
(
0
,
numpy
.
sum
(
iniCOM
-
newCOM
))
self
.
assertGreater
(
1.0
,
newVol
/
iniVol
)
def
convexFillHoles
(
self
):
# Generate two spheres
grain1
=
spam
.
label
.
label
.
Spheroid
(
15
,
15
,
numpy
.
asarray
([
0
,
1
,
0
])).
digitize
()
grain1
=
numpy
.
pad
(
grain1
,
(
5
),
'constant'
,
constant_values
=
(
0
))
grain1
=
numpy
.
where
(
grain1
,
1
,
0
)
grain2
=
spam
.
label
.
label
.
Spheroid
(
15
,
15
,
numpy
.
asarray
([
0
,
1
,
0
])).
digitize
()
grain2
=
numpy
.
pad
(
grain2
,
(
5
),
'constant'
,
constant_values
=
(
0
))
grain2
=
numpy
.
where
(
grain2
,
2
,
0
)
grainIm
=
numpy
.
concatenate
((
grain1
,
grain2
))
grainIm
=
numpy
.
zeros
(
grainIm
.
shape
)
grainIm
[:
grain1
.
shape
[
0
]
-
1
,:,:]
=
grain1
[:
grain1
.
shape
[
0
]
-
1
,:,:]
grainIm
[
grain2
.
shape
[
0
]
-
5
:
-
5
,:,:]
=
grainIm
[
grain2
.
shape
[
0
]
-
5
:
-
5
,:,:]
+
grain2
[:,:,:]
grainIm
=
grainIm
.
astype
(
int
)
# Compute initial volume & COM
COM
=
spam
.
label
.
centresOfMass
(
grainIm
)
iniVol
=
spam
.
label
.
volumes
(
grainIm
).
astype
(
int
)
# Dry run of the function
res1
=
spam
.
label
.
convexFillHoles
(
grainIm
)
# Compute new volume
res1Vol
=
spam
.
label
.
volumes
(
res1
).
astype
(
int
)
# Test#1 -> Check that the volumes are the same
self
.
assertEqual
(
res1Vol
[
1
],
iniVol
[
1
])
self
.
assertEqual
(
res1Vol
[
2
],
iniVol
[
2
])
# Add a marker in the center of one of the labels
grainIm
[
COM
[
1
][
0
].
astype
(
int
),
COM
[
1
][
1
].
astype
(
int
),
COM
[
1
][
2
].
astype
(
int
)]
=
2
# Run again
res2
=
spam
.
label
.
convexFillHoles
(
grainIm
)
# Compute final volume
endVol
=
spam
.
label
.
volumes
(
res2
).
astype
(
int
)
# Compare volumes
normVol1
=
(
endVol
[
1
]
-
iniVol
[
1
])
/
iniVol
[
1
]
normVol2
=
(
endVol
[
2
]
-
iniVol
[
2
])
/
iniVol
[
2
]
# Test#2 -> Check that Vol1 is the same and Vol2 increased
self
.
assertAlmostEqual
(
normVol1
,
0
,
places
=
3
)
self
.
assertGreater
(
normVol2
,
0
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment