Skip to content

Conversation

@uturkbey
Copy link
Collaborator

Bug fix for the edge detection wrap-around issue mentioned in #167:

  • np.roll operations are changed to scipy.ndimage.convolve with a 4-neighborhood Laplacian edge detection kernel.
  • Tested over various real and synthetic brain masks, and outputs are found to be identical to baseline for brain-not-touching-edge cases.
  • SciPY already in project dependencies.
  • Runtime and peak memory usage are benchmarked against baseline and another solution (np.pad before np.roll). Summarized results are as below.
    image

@uturkbey
Copy link
Collaborator Author

Please also see #167 (comment)

@neuronflow
Copy link
Collaborator

neuronflow commented Jan 28, 2026

@uturkbey thanks! Please try to fix the failing tests. Unfortunately, you cannot use our brainless bot for black formatting because the PR does not belong to the repo.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a critical bug in the Quickshear defacing algorithm where edge detection produced incorrect results when brain masks touch array boundaries. The issue was caused by np.roll operations creating artificial wrap-around edges on opposite boundaries.

Changes:

  • Replaced np.roll-based edge detection with scipy.ndimage.convolve using a 4-neighborhood Laplacian kernel
  • Added import for convolve from scipy.ndimage
  • Applied mode='constant', cval=0.0 to prevent boundary wrap-around

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@neuronflow
Copy link
Collaborator

@uturkbey @copilot I am wondering whether it would be enough to simply pad with background and crop after the operation instead of the whole convolution?

Shall we have a call and discuss soon?

@uturkbey
Copy link
Collaborator Author

@uturkbey @copilot I am wondering whether it would be enough to simply pad with background and crop after the operation instead of the whole convolution?

Shall we have a call and discuss soon?

For sure, writing you an email!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants