File size: 762 Bytes
a4ba047
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Describe how a NiFreeze work brainmask differs from the input mask."""

import sys

import nibabel as nb
import numpy as np
from scipy import ndimage

ref = np.asarray(nb.load(sys.argv[1]).dataobj).astype(bool)
d = np.asarray(nb.load(sys.argv[2]).dataobj)
print("work unique values", np.unique(d, return_counts=True))
b = d.astype(bool)
print("ref voxels", int(ref.sum()), "work voxels", int(b.sum()))
print("work-only", int((b & ~ref).sum()), "ref-only", int((ref & ~b).sum()))
for it in (1, 2, 3):
    dil = ndimage.binary_dilation(ref, iterations=it)
    ero = ndimage.binary_erosion(ref, iterations=it)
    print(
        "dilate",
        it,
        bool(np.array_equal(dil, b)),
        "erode",
        it,
        bool(np.array_equal(ero, b)),
    )