Created
July 17, 2020 18:47
-
-
Save d-v-b/bcb7da36b89aba5b9084b30222f20875 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.ndimage.filters import gaussian_filter | |
import numpy as np | |
def generate_mask(array, sigma, percentile, percentile_downsampling=100, threshold=.4): | |
smoothed = gaussian_filter(array, sigma=sigma, mode='nearest') | |
lower = np.percentile(smoothed.ravel()[::percentile_downsampling], percentile) | |
mean = smoothed.mean() | |
level = lower + (threshold * (mean - lower)) | |
mask = (smoothed > level).astype(array.dtype) | |
return mask | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment