Skip to content

Commit d39e7f4

Browse files
authored
Merge pull request #170 from uturkbey/167-bug-quickshear-edge-mask-calculation-issue
Fix quickshear edge detection wrap-around issue by using convolution
2 parents 54916e5 + 91323b3 commit d39e7f4

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

brainles_preprocessing/defacing/quickshear/nipy_quickshear.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import nibabel as nb
1212
import numpy as np
1313
from numpy.typing import NDArray
14+
from scipy.ndimage import convolve
1415

1516
try:
1617
from duecredit import BibTeX, due
@@ -83,14 +84,9 @@ def edge_mask(mask):
8384
brain = mask.any(axis=0)
8485

8586
# Simple edge detection
86-
edgemask = (
87-
4 * brain
88-
- np.roll(brain, 1, 0)
89-
- np.roll(brain, -1, 0)
90-
- np.roll(brain, 1, 1)
91-
- np.roll(brain, -1, 1)
92-
!= 0
93-
)
87+
kernel = np.array([[0, -1, 0], [-1, 4, -1], [0, -1, 0]])
88+
edgemask = convolve(brain, kernel, mode="constant", cval=0.0) != 0
89+
9490
return edgemask.astype("uint8")
9591

9692

0 commit comments

Comments
 (0)