[030aeb]: / tests / tissues / test_tissue.py

Download this file

32 lines (21 with data), 833 Bytes

 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
import unittest
import numpy as np
from dosma.tissues.tissue import largest_cc
class TestLargestCC(unittest.TestCase):
def test_largest_cc(self):
# smallest cc
a = np.zeros((100, 100)).astype(np.uint8)
a[:10, :10] = 1
# medium cc
b = np.zeros((100, 100)).astype(np.uint8)
b[85:, 85:] = 1
# largest cc
c = np.zeros((100, 100)).astype(np.uint8)
c[25:75, 25:75] = 1
mask = a | b | c
assert np.all(largest_cc(mask) == c) # only largest cc returned
assert np.all(largest_cc(mask, num=2) == (b | c)) # largest 2 cc
assert np.all(largest_cc(mask, num=3) == (a | b | c)) # largest 3 cc
assert np.all(largest_cc(mask, num=4) == (a | b | c)) # only 3 cc, return all
if __name__ == "__main__":
unittest.main()