Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions brainles_preprocessing/defacing/quickshear/nipy_quickshear.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,16 @@ def run_quickshear(bet_img: nb.nifti1.Nifti1Image, buffer: int = 10) -> NDArray:
slope = ydiffs[0] / xdiffs[0]

yint = low[1][0] - (low[0][0] * slope) - buffer
ys = np.arange(0, mask_RPS.shape[2]) * slope + yint
ys = np.arange(0, mask_RPS.shape[1]) * slope + yint
defaced_mask_RPS = np.ones(mask_RPS.shape, dtype="bool")

for x, y in zip(np.nonzero(ys > 0)[0], ys.astype(int)):
defaced_mask_RPS[:, x, :y] = 0
for x in np.nonzero(ys > 0)[0]:
# Read the cutoff from ys[x]: zipping the filtered indices with the
# unfiltered ys array pairs each position with the wrong cutoff
# whenever ys starts with a nonpositive prefix, and a negative cutoff
# would make the slice erase the wrong region.
y_clipped = min(int(ys[x]), mask_RPS.shape[2])
defaced_mask_RPS[:, x, :y_clipped] = 0

defaced_mask = nb.orientations.apply_orientation(defaced_mask_RPS, from_RPS)

Expand Down
Loading